size property
Returns the number of entries in the cache.
Expired entries should not be counted.
Implementation
@override
int get size {
// Count only non-expired entries
var count = 0;
for (final key in _storageBox.keys) {
final json = _storageBox.get(key);
if (json == null) continue;
try {
final entry = CacheEntry.fromJson(Map<String, dynamic>.from(json));
if (!entry.isExpired) {
count++;
}
} on Exception catch (e, s) {
log(
'HiveCacheStore: Failed to deserialize cache entry for key "$key": $e',
level: 900,
stackTrace: s,
);
// Skip corrupted entries
continue;
}
}
return count;
}