cache method

  1. @override
Future<Uint8List?> cache(
  1. DownloadTask task
)
override

Retrieves cached data for the given task from memory or file.

Returns a Uint8List containing the cached data if available, or null if the data is not cached.

Implementation

@override
Future<Uint8List?> cache(DownloadTask task) async {
  Uint8List? dataMemory = await LruCacheSingleton().memoryGet(task.matchUrl);
  if (dataMemory != null) {
    logD('From memory: ${dataMemory.lengthInBytes.toMemorySize}');
    return dataMemory;
  }
  Uint8List? dataFile = await LruCacheSingleton().storageGet(task.matchUrl);
  if (dataFile != null) {
    logD('From file: ${task.matchUrl}');
    await LruCacheSingleton().memoryPut(task.matchUrl, dataFile);
    return dataFile;
  }
  return null;
}