CacheStorage class abstract

Storage backend for the cache layer.

Default implementation is InMemoryCacheStorage (no dependencies).

Swap in your own for persistent storage:

class HiveCacheStorage implements CacheStorage {
  @override Future<String?> get(String key) async => Hive.box('cache').get(key);
  @override Future<void>    set(String key, String value, Duration ttl) async {
    await Hive.box('cache').put(key, value);
    // store expiry separately, etc.
  }
  @override Future<void> delete(String key) => Hive.box('cache').delete(key);
  @override Future<void> clear()            => Hive.box('cache').clear();
}

ApiCache.storage = HiveCacheStorage();
Implementers

Constructors

CacheStorage()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Wipe the entire cache.
delete(String key) Future<void>
Delete a single entry.
get(String key) Future<String?>
Retrieve a previously stored value, or null if missing / expired.
keys() Future<List<String>>
Return all keys (used by pattern-based invalidation).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
set(String key, String value, Duration ttl) Future<void>
Store value under key with the given TTL.
toString() String
A string representation of this object.
inherited

Operators

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