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

hashCode int
The hash code for this object.
no setterinherited
maxSize int?
Maximum number of entries. If null, unlimited.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Returns the number of entries in the cache.
no setteroverride

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