CacheRepository class final
A store wrapped with a key prefix and the high-level API
(remember, flexible, lock, …).
Constructors
- CacheRepository(CacheStore store, {String prefix = '', CacheStore? lockStore, String? lockPrefix})
-
A repository over
store, prefixing every key withprefix(as the store shapes it, when it is CachePrefixShaping).
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- lockStore → CacheStore?
-
Store used for stampede locks when store cannot lock atomically
across isolates (defaults to store).
final
- prefix → String
-
The key prefix.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scope → StateScope
-
The store's scope.
no setter
- store → CacheStore
-
The store holding the values.
final
Methods
-
add(
String key, Object? value, {Duration? ttl}) → Future< bool> -
Stores
valueonly whenkeyis missing; returns whether it did. -
decrement(
String key, [int by = 1]) → Future< int> -
Subtracts
byfrom the integer underkey. -
flexible<
T> (String key, (Duration, Duration) window, FutureOr< T> compute()) → Future<T> -
Stale-while-revalidate (Laravel 11
Cache::flexible): fresh forfresh, served stale and refreshed in the background untilstale, recomputed inline afterwards. -
flush(
) → Future< void> - Removes every value of the store.
-
forever(
String key, Object? value) → Future< void> -
Stores
valueunderkeywith no expiry. -
forget(
String key) → Future< bool> -
Removes
key; returns whether it existed. -
get<
T> (String key, [T? fallback]) → Future< T?> -
The value of
key, orfallbackwhen missing. -
has(
String key) → Future< bool> -
Whether
keyholds a value. -
increment(
String key, [int by = 1]) → Future< int> -
Adds
byto the integer underkey. -
lock(
String name, {Duration ttl = const Duration(seconds: 10), String? owner}) → Lock -
An atomic lock named
name. -
many(
List< String> keys) → Future<Map< String, Object?> > -
The values of
keys, null for the missing ones. -
missing(
String key) → Future< bool> -
Whether
keyholds nothing. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pull<
T> (String key, [T? fallback]) → Future< T?> - Returns and removes the value.
-
put(
String key, Object? value, {Duration? ttl}) → Future< void> -
Stores
valueunderkey, forttlor forever. -
putMany(
Map< String, Object?> values, {Duration? ttl}) → Future<void> -
Stores every entry of
values. -
remember<
T> (String key, Duration? ttl, FutureOr< T> compute(), {Duration lockTimeout = const Duration(seconds: 10)}) → Future<T> - Gets or computes-and-stores. Computation is guarded by a per-key lock so only one caller recomputes (stampede protection); others wait and read the fresh value.
-
rememberForever<
T> (String key, FutureOr< T> compute()) → Future<T> -
The value of
key, orcompute's result stored forever. -
This cache with its entries tagged
names(Laravel'sCache::tags):flush()on it forgets only what those tags hold. Reads use the same tags, in the same order. UnsupportedError on stores that cannot tag (file,database), as Laravel'sBadMethodCallException. -
toString(
) → String -
A string representation of this object.
inherited
-
touch(
String key, Duration ttl) → Future< bool> -
Laravel's
Cache::touch(): a newttlforkey, keeping its value.falsewhen it is missing, and attlof zero or less forgets it.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited