getOrAddSync<T> method

  1. @override
T getOrAddSync<T>(
  1. String key, {
  2. required T addValue,
  3. bool autoRemove = true,
  4. Duration expiration = const Duration(seconds: 60),
  5. bool listen = true,
})
override

Try to get a value from the cache by key. if the key is not in the cache, will be created sync.

Implementation

@override
T getOrAddSync<T>(
  String key, {
  required T addValue,
  bool autoRemove = true,
  Duration expiration = const Duration(seconds: 60),
  bool listen = true,
}) {
  if (contains(key)) {
    return _cache[key] as T;
  } else {
    add(
      key,
      addValue,
      autoRemove: autoRemove,
      expiration: expiration,
      listen: listen,
    );
    _notifyListeners();
    return addValue;
  }
}