readCache method

Cache? readCache(
  1. String key
)

Retrieves the cached response for the given key.

Returns null if the cache entry does not exist or fails to load.

Implementation

Cache? readCache(String key) {
  switch (cacheSource) {
    case CacheSource.memory:
      return _cacheMemory[key];
    case CacheSource.file:
      try {
        var file = File(
          joinPaths([FinchApp.config.pathCache, "cache_$key.json"]),
        );
        var content = file.readAsStringSync();
        var jsonContent = jsonDecode(content);
        return Cache.fromJson(jsonContent);
      } catch (e) {
        return null;
      }
  }
}