Is it possible to simply cache every search with a CachingWrapperFilter?

Using Lucene.Net 3.0.3, it’s very simple to wrap every request created in response to a user search in a CachingWrapperFilter . Would this be a bad idea because Lucene will consume more and more memory, or Lucene will manage the memory and release the cached items smartly way?

Should I be selective in the queries that I wrap in a CachingWrapperFilter?

 Query query = .... QueryWrapperFilter queryFilter = new QueryWrapperFilter(query); CachingWrapperFilter cachingFilter = new CachingWrapperFilter(queryFilter); searcher.search(query, cachingFilter, 1); 

Update

The Lucene.Net implementation of the CachingWrapperFilter also uses the mechanism associated with the Garbage Collection. It implements the WeakDictionary class, which is used using instances of the WeakReference class. This is a built-in .Net class that wraps any object and provides a way to check whether this object was built or not. This tells me that the answer to my question is "Yes." Lucene's cache memory management will be under control, as it is essentially tied to the runtime garbage collector, and cache items are retained as long as they are still valid.

A bit more ...

Cache keys are provided by IndexReader before they are wrapped in WeakReference . IndexReader manages the objects that it provides as cache keys. When they cease to function, they are removed and garbage is subsequently collected. The cache then detects this through WeakReference and removes the item from the cache.

Through the "Weak Link" IndexReader and cache can be disabled. The IndexReader element controls the validity of cache elements by deleting key objects, and the cache is cleared.

+4
source share
1 answer

In Java Lucene, this particular cache uses WeakHashMap , which means that records will be automatically cleared after increasing memory pressure. If .NET has an instance for WeakHashMap , I expect it to be used as well.

+3
source

All Articles