InMemoryCacheStore class
In-memory cache store implementation with LRU eviction.
This is the default cache store that doesn't require any external dependencies. Data is stored in memory and will be lost when the application restarts.
Features:
- Fast O(1) lookups, inserts, and deletes
- Optional size limit with LRU (Least Recently Used) eviction
- Automatic expiration of TTL-based entries
- Thread-safe operations
Example:
final store = InMemoryCacheStore(maxSize: 100);
store.set('key', CacheEntry(
data: {'user': 'John'},
timestamp: DateTime.now(),
ttl: Duration(minutes: 5),
));
- Implemented types
Constructors
- InMemoryCacheStore({int? maxSize})
- Creates an in-memory cache store.
Properties
Methods
-
clear(
) → void -
Clears all entries from the cache.
override
-
contains(
String key) → bool -
Checks if a key exists in the cache and is not expired.
override
-
delete(
String key) → void -
Deletes a cache entry by its key.
override
-
evictExpired(
) → void -
Removes all expired entries from the cache.
override
-
get(
String key) → CacheEntry? -
Retrieves a cache entry by its key.
override
-
getAll(
) → Map< String, CacheEntry> -
Returns all cache entries as a map.
override
-
getStats(
) → Map< String, dynamic> - Returns statistics about the cache.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
set(
String key, CacheEntry entry) → void -
Stores a cache entry with the given key.
override
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited