put method

  1. @override
Future<FileSystemEntity?> put(
  1. String key,
  2. FileSystemEntity value
)
override

Inserts or updates the file for the given key in the cache.

Returns the previous file if it existed, or null otherwise. Updates the cache size and triggers eviction if necessary. The operation is thread-safe.

Implementation

@override
Future<FileSystemEntity?> put(String key, FileSystemEntity value) async {
  assert(key.isNotEmpty, 'key must not be empty');
  return await lock.synchronized(() async {
    putCount++;
    size += (await value.stat()).size;

    final FileSystemEntity? previous = map[key];
    if (previous != null) {
      size -= (await previous.stat()).size;
    }
    map[key] = value;

    trimToSize(maxSize);
    return previous;
  });
}