fetchCacheData<R, T> method

Future<R?> fetchCacheData<R, T>(
  1. String key,
  2. SerializerBloc<R, T> serializerBloc,
  3. Storage storage, {
  4. bool keepExpiredCache = false,
  5. int ttlValue = defaultTTLValue,
})

Implementation

Future<R?> fetchCacheData<R, T>(
    String key, SerializerBloc<R, T> serializerBloc, Storage storage,
    {bool keepExpiredCache = false, int ttlValue = defaultTTLValue}) async {
  final cacheWrapper = await read<T>(key, storage);
  if (cacheWrapper == null) {
    return null;
  }

  logCacheData(key, cacheWrapper, storage: storage, ttlValue: ttlValue);

  if (cacheWrapper.expired(ttlValue, ignoreTtl: keepExpiredCache)) {
    return null;
  }
  if (cacheWrapper.data == null) {
    return null;
  }
  return serializerBloc(cacheWrapper.data as T);
}