get method
Get cached data
Implementation
Future<CachedData<T>?> get(String key) async {
try {
final jsonString = await storage.load('$prefix$key');
if (jsonString == null) return null;
// Deserialize from JSON
final json = jsonDecode(jsonString) as Map<String, dynamic>;
final cachedAt = DateTime.parse(json['cachedAt'] as String);
final data = json['data'] as T;
final cached = CachedData<T>(
data: data,
cachedAt: cachedAt,
);
if (cached.isExpired) {
await remove(key);
return null;
}
return cached;
} catch (e) {
debugPrint('Error reading from disk cache: $e');
return null;
}
}