Cache<K, V> constructor

Cache<K, V>({
  1. required CacheStorage<K, CacheEntry<K, V>> storage,
  2. required EvictionAlgorithm algorithm,
  3. required int maxSize,
  4. required Future<V> loader(
    1. K key
    ),
})

Creates a new cache instance.

storage - The storage implementation to use for caching algorithm - The eviction algorithm to use (LFU or LRU) maxSize - Maximum number of items to store in the cache loader - Callback function to load values from backing store

Implementation

Cache({
  required CacheStorage<K, CacheEntry<K, V>> storage,
  required EvictionAlgorithm algorithm,
  required int maxSize,
  required Future<V> Function(K key) loader,
})  : _storage = storage,
      _algorithm = algorithm,
      _maxSize = maxSize,
      _loader = loader;