isCacheValid method

Future<bool> isCacheValid()

Check if cache is valid

Implementation

Future<bool> isCacheValid() async {
  try {
    final prefs = await SharedPreferences.getInstance();

    if (!prefs.containsKey(_cacheKey)) {
      return false;
    }

    final timestamp = prefs.getInt(_timestampKey);
    if (timestamp == null) return false;

    final cacheDate = DateTime.fromMillisecondsSinceEpoch(timestamp);
    final age = DateTime.now().difference(cacheDate);

    return age <= _cacheExpiry;
  } catch (e) {
    return false;
  }
}