public final class UsageTrackingQueryCachingPolicy extends java.lang.Object implements QueryCachingPolicy
QueryCachingPolicy
that tracks usage statistics of recently-used
filters in order to decide on which filters are worth caching.Modifier and Type | Field and Description |
---|---|
private FrequencyTrackingRingBuffer |
recentlyUsedFilters |
private static int |
SENTINEL |
ALWAYS_CACHE
Constructor and Description |
---|
UsageTrackingQueryCachingPolicy()
Create a new instance with an history size of 256.
|
UsageTrackingQueryCachingPolicy(int historySize)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
(package private) int |
frequency(Query query) |
(package private) static boolean |
isCheap(Query query) |
(package private) static boolean |
isCostly(Query query) |
private static boolean |
isPointQuery(Query query) |
protected int |
minFrequencyToCache(Query query)
For a given query, return how many times it should appear in the history
before being cached.
|
void |
onUse(Query query)
Callback that is called every time that a cached filter is used.
|
boolean |
shouldCache(Query query)
Whether the given
Query is worth caching. |
private static final int SENTINEL
private final FrequencyTrackingRingBuffer recentlyUsedFilters
public UsageTrackingQueryCachingPolicy(int historySize)
historySize
- the number of recently used filters to trackpublic UsageTrackingQueryCachingPolicy()
private static boolean isPointQuery(Query query)
static boolean isCostly(Query query)
static boolean isCheap(Query query)
protected int minFrequencyToCache(Query query)
public void onUse(Query query)
QueryCachingPolicy
onUse
in interface QueryCachingPolicy
int frequency(Query query)
public boolean shouldCache(Query query) throws java.io.IOException
QueryCachingPolicy
Query
is worth caching.
This method will be called by the QueryCache
to know whether to
cache. It will first attempt to load a DocIdSet
from 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.shouldCache
in interface QueryCachingPolicy
java.io.IOException