getMoviesWithCacheInfo method

Future<CacheResult<List<Movie>>?> getMoviesWithCacheInfo(
  1. CacheCategory category
)

Get movies with cache information.

Implementation

Future<CacheResult<List<Movie>>?> getMoviesWithCacheInfo(
  CacheCategory category,
) async {
  await _ensureInitialized();
  try {
    final timestamp = _timestampBox!.get(category.value);
    final isValid = await isCacheValid(category);

    if (!isValid || timestamp == null) return null;

    final movies = await getCachedMoviesForCategory(category);
    if (movies == null || movies.isEmpty) return null;

    final cacheAge = DateTime.now().difference(timestamp);

    return CacheResult(
      data: movies,
      fromCache: true,
      cacheAge: cacheAge,
      cachedAt: timestamp,
    );
  } catch (e) {
    debugPrint(
        'Error getting movies with cache info for ${category.value}: $e');
    return null;
  }
}