get method

  1. @override
Future<FileSystemEntity?> get(
  1. String key
)
override

Retrieves the file associated with the given key, or null if not present or does not exist.

Updates hit/miss statistics accordingly. The operation is thread-safe.

Implementation

@override
Future<FileSystemEntity?> get(String key) async {
  assert(key.isNotEmpty, 'key must not be empty');
  return await lock.synchronized(() async {
    final FileSystemEntity? entity = map[key];
    final File? file = entity is File ? entity : null;
    if (file != null && await file.exists()) {
      // LinkedHashMap is insertion-ordered, so reinsert on hit to make
      // eviction approximate access-order LRU instead of creation order.
      map.remove(key);
      map[key] = file;
      hitCount++;
      return file;
    }
    if (entity != null) {
      // The file disappeared outside the cache. Drop only the index entry so
      // later trims do not see an empty map with a non-zero size ledger.
      await _removeEntryLocked(key, deleteFile: false);
    }
    missCount++;
    return null;
  });
}