cacheResult method
- SearchResult result
Caches a search result.
Stores the result associated with the query. The result will expire
after cacheDuration and will not be returned by getCachedResult.
Automatically evicts oldest entries if cache limits are exceeded.
Implementation
Future<void> cacheResult(SearchResult result) async {
_ensureInitialized();
// Check entry limit and evict if needed
if (_box!.length >= maxEntries) {
await _evictOldest();
}
final data = {
'query': result.query,
'timestamp': DateTime.now().millisecondsSinceEpoch,
'items': result.items.map(_serializeItem).toList(),
'totalCount': result.totalCount,
'executionTimeMs': result.executionTimeMs,
'hasMore': result.hasMore,
'nextPage': result.nextPage,
};
await _box!.put(result.query.toLowerCase(), data);
}