operator []= method

  1. @override
void operator []=(
  1. Snowflake key,
  2. T value
)
override

Associates the key with the given value.

If the key was already in the map, its associated value is changed. Otherwise the key/value pair is added to the map.

Implementation

@override
void operator []=(Snowflake key, T value) {
  assert(value is! ManagedSnowflakeEntity || value.id == key, 'Mismatched entity key in cache');

  if (config.shouldCache?.call(value) == false) {
    remove(key);
    return;
  }

  _store.update(
    (identifier: identifier, key: key),
    (entry) => entry
      ..value = value
      ..accessCount ~/= 2,
    ifAbsent: () => _CacheEntry(value),
  );

  scheduleFilterItems();
}