
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.
QueryCache(int)
Initialises a new QueryCache with the specified maximum entry count.
Count
Approximate 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 skipped on next access.
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.
Put(Query, int, TopDocs, string)
Stores a result using an additional immutable result identity.
TryGet(Query, int)
Tries to retrieve a cached result. Returns null on miss. Lock-free on the read path.
TryGet(Query, int, string)
Tries to retrieve a result using an additional immutable result identity.