NyTestCache class

In-memory cache implementation for testing.

This class provides a memory-based cache that mimics the behavior of NyCache without requiring file system access.

Example:

final cache = NyTestCache();
await cache.put('key', 'value', seconds: 60);
final value = await cache.get<String>('key');

Properties

count int
Get count of entries.
no setter
entries Map<String, dynamic>
Get all entries (for debugging).
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Check if cache is empty.
no setter
isNotEmpty bool
Check if cache is not empty.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear(String key) Future<void>
Removes a specific item from the cache.
documents() Future<List<String>>
Retrieves a list of all cache keys.
flush() Future<void>
Removes all items from the cache.
get<T>(String key) Future<T?>
Retrieves a value from the cache.
has(String key) Future<bool>
Checks if a specific key exists in the cache.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put<T>(String key, T value, {int? seconds}) Future<void>
Stores a value in the cache.
saveForever<T>(String key, Future<T> callback()) Future<T>
Saves a value in the cache without an expiration time.
saveRemember<T>(String key, int seconds, dynamic callback()) Future<T>
Saves a value in the cache with an expiration time.
size() Future<int>
Calculates the total size of the cache in bytes (approximate).
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

getInstance() NyTestCache
Get a singleton instance of the test cache.
resetInstance() → void
Reset the singleton instance (useful between tests).