DefaultCache constructor

DefaultCache(
  1. CacheStore storage, {
  2. String? name,
  3. ExpiryPolicy? expiryPolicy,
  4. KeySampler? sampler,
  5. EvictionPolicy? evictionPolicy,
  6. int? maxEntries,
  7. CacheLoader? cacheLoader,
  8. Clock? clock,
  9. EventListenerMode? eventListenerMode,
})

Builds a DefaultCache out of a mandatory CacheStore and a set of optional configurations

  • storage: The CacheStore
  • 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 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

Returns a DefaultCache

Implementation

DefaultCache(this.storage,
    {String? name,
    ExpiryPolicy? expiryPolicy,
    KeySampler? sampler,
    EvictionPolicy? evictionPolicy,
    int? maxEntries,
    CacheLoader? cacheLoader,
    Clock? clock,
    EventListenerMode? eventListenerMode})
    : 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.value()),
      clock = clock ?? Clock(),
      eventPublishingMode = eventListenerMode ?? EventListenerMode.disabled,
      streamController = StreamController.broadcast(
          sync: eventListenerMode == EventListenerMode.synchronous);