Cache class

Cache facade on top of dox_cache.

Stores come from AppConfig.cache. Each store is built once per isolate.

await Cache().put('foo', 'bar', duration: Duration(minutes: 5));
await Cache().store('redis').get('foo');
await Cache().tag('users').flush();

Values must be JSON types (Map, List, String, num, bool).

Constructors

Cache({CacheManager? manager})
manager is the dox_cache CacheManager. Default is Dox().cache.

Properties

hashCode → int
The hash code for this object.
no setterinherited
repository → CacheStore
The dox_cache store, for the methods that are not here.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(String key, Object? value, {Duration? duration}) → Future<bool>
Store only when the key is missing. True when it was stored.
decrement(String key, [int by = 1]) → Future<int>
Take by from an integer. A missing key starts at 0.
flush() → Future<void>
Remove all items of the store (or of the tag).
forever(String key, Object? value) → Future<void>
Store a value forever.
forget(String key) → Future<bool>
Remove a key.
get(String key, [Object? defaultValue]) → Future
Get a value, or defaultValue when it is missing.
has(String key) → Future<bool>
True when the key has a value.
increment(String key, [int by = 1]) → Future<int>
Add by to an integer. A missing key starts at 0.
lock(String name, [Duration? ttl, String? owner]) → CacheLock
An atomic lock. Memory and Redis stores support it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pull(String key, [Object? defaultValue]) → Future
Get a value and remove it.
put(String key, Object? value, {Duration? duration}) → Future<void>
Store a value. No duration means forever.
remember<T>(String key, Duration? duration, FutureOr<T> compute()) → Future<T>
The cached value, or run compute and store the result.
rememberForever<T>(String key, FutureOr<T> compute()) → Future<T>
Like remember, but the value never expires.
store(String store) → Cache
Use the store with this name from the config.
tag(String name) → Cache
Put the items under a tag, so you can flush only this tag.
tags(List<String> names) → Cache
Same as tag, with many tags.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited