GenericCache<T> constructor

GenericCache<T>(
  1. Store<CacheInfo, CacheEntry> storage, {
  2. CacheManager? manager,
  3. String? name,
  4. ExpiryPolicy? expiryPolicy,
  5. KeySampler? sampler,
  6. EvictionPolicy? evictionPolicy,
  7. int? maxEntries,
  8. CacheLoader<T>? cacheLoader,
  9. Clock? clock,
  10. EventListenerMode? eventListenerMode,
  11. bool? statsEnabled,
  12. CacheStats? stats,
})

Builds a GenericCache out of a mandatory Store and a set of optional configurations

  • storage: The Store
  • manager: An optional CacheManager
  • name: The name of the cache
  • expiryPolicy: The expiry policy to use, defaults to EternalExpiryPolicy if not provided
  • sampler: The sampler to use upon eviction of a cache element, defaults to FullSampler if not provided
  • evictionPolicy: The eviction policy to use, defaults to LfuEvictionPolicy if not provided
  • maxEntries: The max number of entries this cache can hold if provided. To trigger the eviction policy this value should be provided
  • cacheLoader: The CacheLoader, that should be used to fetch a new value upon absence or expiration
  • clock: The source of time to be used on this, defaults to the system clock if not provided
  • eventListenerMode: The event listener mode of this cache
  • statsEnabled: If statistics should be collected, defaults to false
  • stats: The statistics instance, defaults to DefaultCacheStats

Returns a GenericCache

Implementation

GenericCache(this.storage,
    {this.manager,
    String? name,
    ExpiryPolicy? expiryPolicy,
    KeySampler? sampler,
    EvictionPolicy? evictionPolicy,
    int? maxEntries,
    CacheLoader<T>? cacheLoader,
    Clock? clock,
    EventListenerMode? eventListenerMode,
    bool? statsEnabled,
    CacheStats? stats})
    : name = name ?? Uuid().v1(),
      expiryPolicy = expiryPolicy ?? const EternalExpiryPolicy(),
      sampler = sampler ?? const FullSampler(),
      evictionPolicy = evictionPolicy ?? const LfuEvictionPolicy(),
      assert(maxEntries == null || maxEntries >= 0),
      maxEntries = maxEntries ?? 0,
      cacheLoader = cacheLoader ?? ((key) => Future<T?>.value()),
      clock = clock ?? Clock(),
      eventPublishingMode = eventListenerMode ?? EventListenerMode.disabled,
      streamController = StreamController.broadcast(
          sync: eventListenerMode == EventListenerMode.synchronous),
      statsEnabled = statsEnabled ?? false,
      stats = stats ?? DefaultCacheStats();