This blog is meant to explain how QueryResultCache and FilterCache are used during the basic query processing in Apache Solr 8.11.0. This blog does not explain how these caches are used during the execution of more advanced components like faceting.
Solr caches are associated with a specific instance of an Index Searcher. By default, elements in the caches don’t expire after a time interval, instead, they remain valid for the lifetime of the Index Searcher. Time-based expiration can be enabled by using the maxIdleTime option. This attribute is expressed in seconds, with the default value of 0 meaning no entries are automatically evicted due to exceeded idle time.
In Solr, the following cache implementations are available: CaffeineCache, LRUCache, FastLRUCache, and LFUCache. CaffeineCache is recommended because it usually offers a lower memory footprint, higher hit ratio, and better multi-threaded performance, all the other caches are in the deprecation path and they will be removed in Solr 9.0.
The Statistics page in the Solr Admin UI displays information about the performance of all the active caches.
If we want to have more details about the keys cached, a new open-source tool is available from December 2021.
The cacheViewHandler [1] is implemented by Shawn Heisey and it offers a rest endpoint to see what are the keys and the number of documents cached for each key.
Bejean
August 1, 2023Hi,
For QueryResultCache, you write “Each entry is associated with the query parameters q (query), fq (filterQuery), sort, and minExactCount”.
start and rows parameters are not discriminants too ?
Dominique
Daniele Antuzi
September 1, 2023Hi Dominique,
if you look at the source code of the cache key, the `start` and `rows` parameters are not discriminant.
The values `start` and `rows` impact the number of elements stored in the cache in the following way.
Given `queryResultWindowSize=20` we have:
start=0, rows=10, the cache keeps the first 20 results
start=10, rows=10, the cache keeps the first 20 results
start=20, rows=10, the cache keeps the first 40 results
That being said, there is another parameter `queryResultMaxDocsCached` so, if `start + rows > queryResultMaxDocsCached`, the cache won’t be used.