- All Implemented Interfaces:
public class UsageTrackingQueryCachingPolicy extends Object implements QueryCachingPolicyA
QueryCachingPolicythat tracks usage statistics of recently-used filters in order to decide on which filters are worth caching.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
minFrequencyToCache(Query query)For a given filter, return how many times it should appear in the history before being cached.
onUse(Query query)Callback that is called every time that a cached filter is used.
shouldCache(Query query)Whether the given
Queryis worth caching.
public UsageTrackingQueryCachingPolicy(int historySize)Expert: Create a new instance with a configurable history size. Beware of passing too large values for the size of the history, either
minFrequencyToCache(org.apache.lucene.search.Query)returns low values and this means some filters that are rarely used will be cached, which would hurt performance. Or
minFrequencyToCache(org.apache.lucene.search.Query)returns high values that are function of the size of the history but then filters will be slow to make it to the cache.
historySize- the number of recently used filters to track
public UsageTrackingQueryCachingPolicy()Create a new instance with an history size of 256. This should be a good default for most cases.
protected int minFrequencyToCache(Query query)For a given filter, return how many times it should appear in the history before being cached. The default implementation returns 2 for filters that need to evaluate against the entire index to build a
MultiTermQuery, point-based queries or
TermInSetQuery, and 5 for other filters.
public void onUse(Query query)Description copied from interface:
QueryCachingPolicyCallback that is called every time that a cached filter is used. This is typically useful if the policy wants to track usage statistics in order to make decisions.
public boolean shouldCache(Query query) throws IOExceptionDescription copied from interface:
QueryCachingPolicyWhether the given
Queryis worth caching. This method will be called by the
QueryCacheto know whether to cache. It will first attempt to load a
DocIdSetfrom the cache. If it is not cached yet and this method returns true then a cache entry will be generated. Otherwise an uncached scorer will be returned.