isCacheValid method

Future<bool> isCacheValid()

Checks if cached CDN config is still valid (within cache duration)

Implementation

Future<bool> isCacheValid() async {
  try {
    final timestampStr = await getValue(_configTimestampKey);
    if (timestampStr == null) return false;

    final timestamp = int.tryParse(timestampStr);
    if (timestamp == null) return false;

    final now = DateTime.now().millisecondsSinceEpoch;

    return (now - timestamp) < _cacheDuration;
  } catch (error) {
    // ignore: avoid_print
    print('Error checking CDN config cache validity: $error');
    return false;
  }
}