get static method
Implementation
static Future<dynamic> get(String key) async {
// memory first
final m = _mem[key];
if (m != null) {
if (!m.expired) { AutoPilotLogger.logCache('HIT(mem)', key); return m.data; }
_mem.remove(key);
}
// disk fallback
try {
final p = await SharedPreferences.getInstance();
final raw = p.getString('ap_cache_$key');
if (raw != null) {
final j = jsonDecode(raw) as Map<String, dynamic>;
final exp = DateTime.fromMillisecondsSinceEpoch(j['exp'] as int);
if (DateTime.now().isBefore(exp)) {
_mem[key] = _Entry(j['data'], exp);
AutoPilotLogger.logCache('HIT(disk)', key);
return j['data'];
} else {
await p.remove('ap_cache_$key');
}
}
} catch (_) {}
AutoPilotLogger.logCache('MISS', key);
return null;
}