getJson static method

Future getJson(
  1. String key
)

Retrieves cached JSON data if it's not expired.

Implementation

static Future<dynamic> getJson(String key) async {
  await _init();
  final String? cachedData = _prefs?.getString('cache_$key');
  if (cachedData == null) return null;

  final Map<String, dynamic> data = json.decode(cachedData);
  final int expiry = data['expiry'] ?? 0;

  if (DateTime.now().millisecondsSinceEpoch > expiry) {
    await _prefs?.remove('cache_$key');
    return null;
  }

  return data['content'];
}