newGenericCache<T> method
Future<Cache<T> >
newGenericCache<T>(
- Store<
CacheInfo, CacheEntry> store, { - String? name,
- dynamic fromEncodable()?,
- ExpiryPolicy? expiryPolicy,
- KeySampler? sampler,
- EvictionPolicy? evictionPolicy,
- int? maxEntries,
- CacheLoader<
T> ? cacheLoader, - Clock? clock,
- EventListenerMode? eventListenerMode,
- bool? statsEnabled,
- CacheStats? stats,
override
Builds a new Cache
store
: The Store that will back this Cachename
: The name of the cachefromEncodable
: The function that converts between the Map representation of the object and the object itself.expiryPolicy
: The expiry policy to use, defaults to EternalExpiryPolicy if not providedsampler
: The sampler to use upon eviction of a cache element, defaults to FullSampler if not providedevictionPolicy
: The eviction policy to use, defaults to LruEvictionPolicy if not providedmaxEntries
: The max number of entries this cache can hold if provided. To trigger the eviction policy this value should be providedcacheLoader
: The CacheLoader that should be used to fetch a new value upon expirationclock
: The source of time to be used on this, defaults to the system clock if not providedeventListenerMode
: The event listener mode of this cachestatsEnabled
: If statistics should be collected, defaults to falsestats
: The statistics instance
Returns a new DefaultCache
Implementation
@override
Future<Cache<T>> newGenericCache<T>(Store<CacheInfo, CacheEntry> store,
{String? name,
dynamic Function(Map<String, dynamic>)? fromEncodable,
ExpiryPolicy? expiryPolicy,
KeySampler? sampler,
EvictionPolicy? evictionPolicy,
int? maxEntries,
CacheLoader<T>? cacheLoader,
Clock? clock,
EventListenerMode? eventListenerMode,
bool? statsEnabled,
CacheStats? stats}) {
final cache = GenericCache<T>(store,
manager: this,
name: name,
expiryPolicy: expiryPolicy,
sampler: sampler,
evictionPolicy: evictionPolicy,
maxEntries: maxEntries,
cacheLoader: cacheLoader,
clock: clock,
eventListenerMode: eventListenerMode,
statsEnabled: statsEnabled,
stats: stats);
_caches[cache.name] = cache;
return store
.create(cache.name, fromEncodable: fromEncodable)
.then((_) => cache);
}