CacheManager class

Scoped cache manager that owns independent MemoryCache and PersistentCache instances for a single MooseAppContext.

CacheManager is created and owned by MooseAppContext. There is no global or static state — each context has its own isolated cache. Two MooseAppContext instances never share cache data.

Access via the widget tree:

// From a widget
final cache = context.moose.cache;
cache.memory.set('temp_token', 'abc123');
final token = cache.memory.get<String>('temp_token');

// Persistent (survives app restarts)
await cache.persistent.set('user_id', '12345');
final userId = await cache.persistent.getString('user_id');

Or directly on MooseAppContext:

appContext.cache.memory.set('key', value);
appContext.cache.persistent.setString('pref', 'value');

Initialise the persistent layer during bootstrap (done automatically by MooseBootstrapper):

await appContext.cache.initPersistent();

Constructors

CacheManager({MemoryCache? memory, PersistentCache? persistent})

Properties

hashCode int
The hash code for this object.
no setterinherited
memory MemoryCache
In-memory cache for fast, session-scoped storage.
final
persistent PersistentCache
Persistent cache backed by SharedPreferences.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearAll() Future<void>
Clear both memory and persistent caches.
clearMemory() → void
Clear only the in-memory cache.
clearPersistent() Future<bool>
Clear only the persistent cache.
dispose() → void
Dispose the memory cache and stop its cleanup timer.
initPersistent() Future<void>
Initialise the persistent cache layer.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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