put method
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;
});
}