DataCacheX class

The main class for interacting with the cache.

DataCacheX provides methods for storing, retrieving, and deleting data. It uses a CacheAdapter to handle the underlying storage.

Example:

Assuming you have a HiveAdapter instance
final hiveAdapter = HiveAdapter(typeAdapterRegistry);
await hiveAdapter.init();

// Create a DataCacheX instance
final dataCache = DataCacheX(hiveAdapter);

// Store a value
await dataCache.put('name', 'John Doe', expiry: Duration(seconds: 30));

// Retrieve a value
final name = await dataCache.get('name');
print(name); // Output: John Doe

// Delete a value
await dataCache.delete('name');

// Clear the cache
await dataCache.clear();

Constructors

DataCacheX(CacheAdapter _cacheAdapter, {CacheAnalytics? analytics, int? maxSize, int? maxItems, EvictionStrategy evictionStrategy = EvictionStrategy.lru, int compressionLevel = 6})
Creates a new instance of DataCacheX.

Properties

analytics CacheAnalytics
Gets the cache analytics instance.
no setter
averageItemSize double
Gets the average size of items in the cache.
no setter
hashCode int
The hash code for this object.
no setterinherited
hitCount int
Gets the number of cache hits.
no setter
hitRate double
Gets the cache hit rate.
no setter
largestItems List<MapEntry<String, int>>
Gets the largest items in the cache.
no setter
missCount int
Gets the number of cache misses.
no setter
mostFrequentlyAccessedKeys List<MapEntry<String, int>>
Gets the most frequently accessed keys.
no setter
mostRecentlyAccessedKeys List<MapEntry<String, DateTime>>
Gets the most recently accessed keys.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
totalSize int
Gets the total size of all items in the cache (estimated).
no setter

Methods

clear() Future<void>
Clears all data from the cache.
containsKey(String key) Future<bool>
Checks if the cache contains a value associated with the given key.
delete(String key) Future<void>
Deletes the value associated with the given key.
deleteAll(List<String> keys) Future<void>
Deletes multiple values associated with the given keys.
get<T>(String key, {Future<T> refreshCallback()?, CachePolicy? policy}) Future<T?>
Retrieves the value associated with the given key.
getAll<T>(List<String> keys, {Map<String, Future<T> Function()>? refreshCallbacks, CachePolicy? policy}) Future<Map<String, T>>
Retrieves multiple values associated with the given keys.
getAnalyticsSummary() Map<String, dynamic>
Gets a summary of the cache analytics.
invalidate(String key) Future<void>
Invalidates the cache entry associated with the given key.
invalidateWhere(bool test(String key, dynamic value)) Future<void>
Invalidates cache entries that match the given test condition.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put<T>(String key, T value, {Duration? expiry, Duration? slidingExpiry, CachePolicy? policy}) Future<void>
Stores a value in the cache with the given key.
putAll<T>(Map<String, T> entries, {Duration? expiry, Duration? slidingExpiry, CachePolicy? policy}) Future<void>
Stores multiple values in the cache with the given keys.
resetMetrics() → void
Resets the cache metrics.
toString() String
A string representation of this object.
inherited

Operators

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