Section navigation

Public classSealed QueryCache

Namespace
Rowles.LeanCorpus.Search.Searcher
Assembly
Rowles.LeanCorpus.dll

Thread-safe query result cache. Entries are keyed by (Query, topN) and invalidated when the commit generation changes. Uses ConcurrentDictionary<TKey, TValue> with generation-swap eviction: readers are lock-free on the common path, and when the soft entry cap is exceeded the entire dictionary is swapped for a fresh one via CompareExchange(ref object, object, object).

public sealed class QueryCache
Inheritance
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.

Recommended placement: hold one cache per SearcherManager rather than per IndexSearcher, and call Invalidate() from the refresh hook.

Public constructor QueryCache(int)

Initialises a new QueryCache with the specified maximum entry count.

Public property Count

Approximate 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 skipped on next access.

Public method Put(Query, int, TopDocs)

Stores a query result in the cache. If the soft entry cap is exceeded, the entire dictionary is swapped for a fresh one.

Public method Put(Query, int, TopDocs, string)

Stores a result using an additional immutable result identity.

Public method TryGet(Query, int)

Tries to retrieve a cached result. Returns null on miss. Lock-free on the read path.

Public method TryGet(Query, int, string)

Tries to retrieve a result using an additional immutable result identity.