CacheManager class

Properties

defaultTTL Duration
final
evictionPolicy EvictionPolicy
final
hashCode int
The hash code for this object.
no setterinherited
maxSize int
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
storage CacheStore
final

Methods

clear() Future<void>
Clear all cache entries
get(dynamic key, Future fetcher(), {Duration? ttl}) Future
Get data from cache or fetch fresh Key can be a String or Map<String, dynamic (like React Query) Users must handle serialization/deserialization themselves
getIfPresent(dynamic key) Future
Get cached data if present and not expired, returns null otherwise Does NOT call fetcher - just returns what's in cache
getMany(List keys) Future<Map<String, dynamic>>
Get multiple entries at once Returns a map of key -> data (only includes keys that exist and are not expired)
getStats() Map<String, dynamic>
Get cache statistics
has(dynamic key) bool
Check if a key exists in cache (without fetching or checking expiration)
invalidate(dynamic key) Future<void>
Invalidate a specific cache entry Key can be a String or Map<String, dynamic
invalidatePattern(String prefix) Future<void>
Invalidate all keys matching a prefix pattern Example: invalidatePattern('user_') removes 'user_123', 'user_456', etc.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(dynamic key, dynamic data, {Duration? ttl}) Future<void>
Manually set data in cache Key can be a String or Map<String, dynamic (like React Query) Users must pass already serialized/prepared data
setMany(Map entries, {Duration? ttl}) Future<void>
Set multiple entries at once
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

create({required int maxSize, required Duration defaultTTL, required EvictionPolicy evictionPolicy, CacheStore? storage}) Future<CacheManager>