RedisCache class
Cache backed by Redis — for shared / distributed caching across processes and hosts.
Values are serialized with jsonEncode on set and decoded on get, so
anything jsonEncode accepts round-trips (strings, numbers, booleans,
nulls, and Map/List of those). Pass prefix to namespace this cache
— [clear] will only drop keys under that prefix.
final cache = await RedisCache.connect(host: 'localhost', port: 6379, prefix: 'app:');
await cache.set('user:42', {'name': 'Eva'}, ttl: Duration(minutes: 5));
final user = await cache.get<Map<String, dynamic>>('user:42');
await cache.close();
- Implemented types
- Available extensions
Properties
Methods
-
clear(
) → Future< void> -
Drops every key under prefix. When prefix is empty this calls
FLUSHDB— wipes the whole database. Otherwise it iterates withSCAN+ batchedDELs so it doesn't block the server on big keyspaces.override -
close(
) → Future< void> -
Releases underlying resources (Redis connection, timers, etc.).
override
-
delete(
String key) → Future< bool> -
Removes
key. Returnstrueif it was present,falseotherwise.override -
get<
T> (String key) → Future< T?> -
Returns the cached value, or
nullwhen the key is absent or expired.override -
has(
String key) → Future< bool> -
Whether
keyis currently present (and unexpired).override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remember<
T> (String key, {Duration? ttl, required Future< T?> builder()}) → Future<T?> -
Available on Cache, provided by the CacheRemember extension
-
set<
T> (String key, T value, {Duration? ttl}) → Future< void> -
Stores
valueunderkey, replacing any previous entry. Whenttlisnullthe entry has no expiration; readers may still evict it (LRU).override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited