SearchCacheRepository class

Repository for caching search results using Hive.

This class provides methods to cache and retrieve search results for offline access and improved performance. Cached results expire after a configurable duration.

Performance features:

  • Maximum entry limit with LRU eviction (default: 50 queries)
  • Maximum size limit (default: 5MB)
  • Automatic cleanup of oldest 20% when limits exceeded

Constructors

SearchCacheRepository.new({required String boxName, Duration cacheDuration = const Duration(hours: 24), int maxEntries = 50, int maxSizeBytes = 5 * 1024 * 1024})
Creates a search cache repository.

Properties

boxName String
Name of the Hive box to store cached results.
final
cacheDuration Duration
Duration for which cached results remain valid.
final
hashCode int
The hash code for this object.
no setterinherited
maxEntries int
Maximum number of cached queries. When exceeded, oldest entries are removed (LRU eviction).
final
maxSizeBytes int
Maximum cache size in bytes. Approximate limit for total cached data.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

cacheResult(SearchResult result) Future<void>
Caches a search result.
clearCache() Future<void>
Clears all cached results.
dispose() Future<void>
Closes the Hive box and releases resources.
getCachedResult(String query) SearchResult?
Retrieves a cached search result.
initialize() Future<void>
Initializes the repository and opens the Hive box.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeExpiredEntries() Future<void>
Removes expired cache entries.
toString() String
A string representation of this object.
inherited

Operators

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