FakeCacheManager class

A fake CacheManager for testing.

Routes all cache operations through an in-memory store instead of a real driver. Supports assertions and operation recording.

final fake = Cache.fake();

await Cache.put('user', 'alice');

fake.assertHas('user');
fake.assertPut('user');
Inheritance

Constructors

FakeCacheManager()

Properties

hashCode int
The hash code for this object.
no setterinherited
recorded List<CacheRecord>
All recorded cache operations in chronological order.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

assertHas(String key) → void
Assert that key currently exists in the cache store.
assertMissing(String key) → void
Assert that key does not exist in the cache store.
assertPut(String key) → void
Assert that key was stored via put at least once.
driver([String? driver]) CacheStore
Get a cache driver instance.
override
flush() Future<void>
Remove all items from the cache.
override
forget(String key) Future<void>
Remove an item from the cache.
override
get(String key, {dynamic defaultValue}) → dynamic
Retrieve an item from the cache by key.
override
has(String key) bool
Determine if an item exists in the cache.
override
init() Future<void>
Initialize the driver (optional async setup).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(String key, dynamic value, {Duration? ttl}) Future<void>
Store an item in the cache for a given number of seconds.
override
reset() → void
Clear the store and all recorded operations.
toString() String
A string representation of this object.
inherited

Operators

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