retrieve method

  1. @override
Future retrieve(
  1. String? correlationId,
  2. String? key
)
override

Retrieves cached value from the cache using its key. If value is missing in the cache or expired it returns null.

  • correlationId (optional) transaction id to trace execution through call chain.
  • key a unique value key. Return Future that receives cached value Throws error.

Implementation

@override
Future<dynamic> retrieve(String? correlationId, String? key) async {
  if (key == null) {
    var err = Exception('Key cannot be null');
    throw err;
  }

  // Get entry from the cache
  CacheEntry? entry = _cache[key]; //.cast<CacheEntry>();

  // Cache has nothing
  if (entry == null) {
    return null;
  }

  // Remove entry if expiration set and entry is expired
  if (_timeout > 0 && entry.isExpired()) {
    _cache.remove(key);
    _count--;
    return null;
  }

  return entry.getValue();
}