get method

V? get(
  1. K key
)

return the element identify by key

Implementation

V? get(K key) {
  if (_loaderFunc != null && !containsKey(key)) {
    if (_internalStorage.length >= _internalStorage.capacity) {
      var garbage = _collectGarbage(_internalStorage.length - _internalStorage.capacity + 1);
      if (onEvict != null) {
        for (var e in garbage) {
          onEvict!(e.key, e.value);
        }
      }
      for (var e in garbage) {
        _internalStorage.remove(e.key);
      }
    }
    _loadFirstValue(key);
  }
  var entry = _get(key);
  if (entry == null) {
    return null;
  }

  // Check if the value hasn't expired
  if (_expiration != null && DateTime.now().difference(entry.insertTime) >= _expiration!) {
    if (_syncValueReloading) {
      _loadValue(entry);
      entry = _get(key);
    } else {
      // Non blocking
      Future(() => _loadValue(entry!));
    }
  }

  entry?.use++;
  entry?.updateUseTime();
  return entry?.value;
}