Cache<T> class abstract

Cache for objects of type T, wrapping a CacheProvider to provide a high-level interface.

Cache entries are accessed using the indexing operator [], this returns a Entry<T> wrapper that can be used to get/set data cached at given key.

Example

final Cache<List<int>> cache = Cache.inMemoryCache(4096);

// Write data to cache
await cache['cached-zeros'].set([0, 0, 0, 0]);

// Read data from cache
var r = await cache['cached-zeros'].get();
expect(r, equals([0, 0, 0, 0]));

A Cache can be fused with a Codec using withCodec to get a cache that stores a different kind of objects. It is also possible to create a chuild cache using withPrefix, such that all entries in the child cache have a given prefix.

Constructors

Cache(CacheProvider<T> provider)
Create a Cache wrapping a CacheProvider.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withCodec<S>(Codec<S, T> codec) Cache<S>
Get a Cache wrapping of this cache by encoding objects of type S as T using the given codec.
withPrefix(String prefix) Cache<T>
Get a Cache wrapping of this cache with given prefix.
withTTL(Duration ttl) Cache<T>
Get a Cache wrapping of this cache with given ttl as default for all entries being set using Entry.set.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String key) Entry<T>
Get Entry wrapping data cached at key.

Static Methods

inMemoryCacheProvider(int maxSize) CacheProvider<List<int>>
Create an in-memory CacheProvider holding a maximum of maxSize cache entries.
redisCacheProvider(Uri connectionString) CacheProvider<List<int>>
Create a redis CacheProvider by connecting using a connectionString on the form redis://<host>:<port>.