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 with prefix (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 value only when key is missing; returns whether it did.
decrement(String key, [int by = 1]) → Future<int>
Subtracts by from the integer under key.
flexible<T>(String key, (Duration, Duration) window, FutureOr<T> compute()) → Future<T>
Stale-while-revalidate (Laravel 11 Cache::flexible): fresh for fresh, served stale and refreshed in the background until stale, recomputed inline afterwards.
flush() → Future<void>
Removes every value of the store.
forever(String key, Object? value) → Future<void>
Stores value under key with 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, or fallback when missing.
has(String key) → Future<bool>
Whether key holds a value.
increment(String key, [int by = 1]) → Future<int>
Adds by to the integer under key.
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 key holds 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 value under key, for ttl or 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, or compute's result stored forever.
tags(List<String> names) → CacheRepository
This cache with its entries tagged names (Laravel's Cache::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's BadMethodCallException.
toString() → String
A string representation of this object.
inherited
touch(String key, Duration ttl) → Future<bool>
Laravel's Cache::touch(): a new ttl for key, keeping its value. false when it is missing, and a ttl of zero or less forgets it.

Operators

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