get method
Retrieves a cache entry by its key.
Returns null if:
- The key doesn't exist
- The entry has expired (implementations should auto-delete expired entries)
Implementations should check CacheEntry.isExpired and automatically delete expired entries before returning null.
Implementation
@override
CacheEntry? get(String key) {
final json = _storageBox.get(key);
if (json == null) return null;
try {
final entry = CacheEntry.fromJson(Map<String, dynamic>.from(json));
// Check expiration
if (entry.isExpired) {
delete(key);
return null;
}
return entry;
} on Exception catch (e, s) {
log(
'HiveCacheStore: Failed to deserialize cache entry for key "$key": $e',
level: 900,
stackTrace: s,
);
// If deserialization fails, remove the corrupted entry
delete(key);
return null;
}
}