get method
Retrieves the cached value for key, or null if it is missing,
expired, or written by an incompatible schema version.
Implementation
Future<Map<String, dynamic>?> get(String key) async {
final file = _file(key);
try {
if (!await file.exists()) return null;
final obj =
json.decode(await file.readAsString()) as Map<String, dynamic>;
if ((obj['_v'] as int?) != _schemaVersion) {
await file.delete();
return null;
}
final exp = obj['_exp'] as int?;
if (exp == null || DateTime.now().millisecondsSinceEpoch > exp) {
await file.delete();
return null;
}
return obj['_data'] as Map<String, dynamic>?;
} catch (_) {
return null;
}
}