add method

  1. @override
void add(
  1. String key,
  2. dynamic value, {
  3. bool autoRemove = true,
  4. Duration expiration = const Duration(seconds: 60),
  5. bool listen = true,
})
override

Add a key/value pair to the cache, if the key is not already in the cache. Specify the duration of the cache entry (default 30 seconds).

Implementation

@override
void add(
  String key,
  dynamic value, {
  bool autoRemove = true,
  Duration expiration = const Duration(seconds: 60),
  bool listen = true,
}) {
  if (_cache.containsKey(key)) {
    update(key, (oldValue) => value);
    return;
  }
  _cache[key] = value;

  if (autoRemove) {
    _autoRemove(key, expiration);
  }

  if (listen) {
    _notifyListeners();
  }
}