Table of Contents

Public classSealed 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
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.

Public constructor QueryCache(int)

Initialises a new QueryCache with the specified maximum entry count.

Public property Count

Current number of cached entries.

Public property Hits

Total cache hits since creation.

Public property Misses

Total cache misses since creation.

Public method Clear()

Clears all entries and resets counters.

Public method Invalidate()

Invalidates all cached entries by bumping the generation. Lazy invalidation: stale entries are removed on next access.

Public method Put(Query, int, TopDocs)

Stores a query result in the cache.

Public method TryGet(Query, int)

Tries to retrieve a cached result. Returns null on miss.