
QueryCache
- Namespace
- Rowles.LeanLucene.Search.Searcher
- Assembly
- Rowles.LeanLucene.dll
Thread-safe LRU query result cache. Entries are keyed by (Query, topN) and invalidated when the commit generation changes.
public sealed class QueryCache
Remarks
Invalidation contract: the cache is keyed against a single commit generation. Callers must invoke Invalidate() (or assign a fresh cache) whenever the underlying searcher is swapped to a newer commit, otherwise stale results may be returned. Cached results are snapshot views: doc IDs and scores reflect the segments visible at the moment of caching, and remain valid for as long as those segments are still referenced by the live searcher.
Recommended placement: hold one cache per SearcherManager rather than per IndexSearcher, and call Invalidate() from the refresh hook. This avoids a write race where two concurrent searches racing against a commit could publish results from differing generations.
QueryCache(int)
Initialises a new QueryCache with the specified maximum entry count.
Count
Current number of cached entries.
Hits
Total cache hits since creation.
Misses
Total cache misses since creation.
Clear()
Clears all entries and resets counters.
Invalidate()
Invalidates all cached entries by bumping the generation. Lazy invalidation: stale entries are removed on next access.
Put(Query, int, TopDocs)
Stores a query result in the cache.
TryGet(Query, int)
Tries to retrieve a cached result. Returns null on miss.