put method

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

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

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

Implementation

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

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

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