HiveCacheStore class

Persistent cache store implementation using Hive.

This store provides persistent storage for cache entries using Hive, a fast, lightweight NoSQL database for Dart and Flutter.

Features:

  • Persistent storage (survives app restarts)
  • Fast O(1) lookups, inserts, and deletes
  • Automatic expiration of TTL-based entries
  • Lazy box opening for better performance

Requirements:

  • Application must initialize Hive before using this store
  • For Flutter: Use path_provider to get a writable directory
  • For Dart: Use Hive.init() with a valid directory path

Example:

// Initialize Hive (once in your app)
Hive.init('/path/to/app/data');

// Open the store
final store = await HiveCacheStore.open('dartpollo_cache');

// Use with DartpolloCachedClient
final client = DartpolloCachedClient(
  'https://api.example.com/graphql',
  cacheStore: store,
);

// Close when done (optional, but recommended)
await store.close();
Implemented types

Properties

hashCode int
The hash code for this object.
no setterinherited
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
close() Future<void>
Closes the underlying Hive box.
compact() Future<void>
Compacts the underlying Hive box to reclaim disk space.
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

Static Methods

open(String boxName) Future<HiveCacheStore>
Opens or creates a Hive cache store.