Add option to expire filter's cache based on access time, closes #803.
This commit is contained in:
parent
0d150e6918
commit
e759b4c971
|
@ -24,11 +24,13 @@ import org.elasticsearch.common.collect.MapMaker;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.docset.DocSet;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.cache.filter.support.AbstractDoubleConcurrentMapFilterCache;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A resident reference based filter cache that has soft keys on the <tt>IndexReader</tt>.
|
||||
|
@ -39,9 +41,12 @@ public class ResidentFilterCache extends AbstractDoubleConcurrentMapFilterCache
|
|||
|
||||
private final int maxSize;
|
||||
|
||||
private final TimeValue expire;
|
||||
|
||||
@Inject public ResidentFilterCache(Index index, @IndexSettings Settings indexSettings) {
|
||||
super(index, indexSettings);
|
||||
this.maxSize = componentSettings.getAsInt("max_size", 1000);
|
||||
this.expire = componentSettings.getAsTime("expire", null);
|
||||
}
|
||||
|
||||
@Override protected ConcurrentMap<Filter, DocSet> buildCacheMap() {
|
||||
|
@ -49,6 +54,9 @@ public class ResidentFilterCache extends AbstractDoubleConcurrentMapFilterCache
|
|||
if (maxSize != -1) {
|
||||
mapMaker.maximumSize(maxSize);
|
||||
}
|
||||
if (expire != null) {
|
||||
mapMaker.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
return mapMaker.makeMap();
|
||||
}
|
||||
|
||||
|
@ -59,6 +67,9 @@ public class ResidentFilterCache extends AbstractDoubleConcurrentMapFilterCache
|
|||
if (maxSize != -1) {
|
||||
mapMaker.maximumSize(maxSize);
|
||||
}
|
||||
if (expire != null) {
|
||||
mapMaker.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
return mapMaker.makeMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ import org.elasticsearch.common.collect.MapMaker;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.docset.DocSet;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.cache.filter.support.AbstractDoubleConcurrentMapFilterCache;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A soft reference based filter cache that has soft keys on the <tt>IndexReader</tt>.
|
||||
|
@ -39,9 +41,12 @@ public class SoftFilterCache extends AbstractDoubleConcurrentMapFilterCache {
|
|||
|
||||
private final int maxSize;
|
||||
|
||||
private final TimeValue expire;
|
||||
|
||||
@Inject public SoftFilterCache(Index index, @IndexSettings Settings indexSettings) {
|
||||
super(index, indexSettings);
|
||||
this.maxSize = componentSettings.getAsInt("max_size", -1);
|
||||
this.expire = componentSettings.getAsTime("expire", null);
|
||||
}
|
||||
|
||||
@Override protected ConcurrentMap<Filter, DocSet> buildCacheMap() {
|
||||
|
@ -51,6 +56,9 @@ public class SoftFilterCache extends AbstractDoubleConcurrentMapFilterCache {
|
|||
if (maxSize != -1) {
|
||||
mapMaker.maximumSize(maxSize);
|
||||
}
|
||||
if (expire != null) {
|
||||
mapMaker.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
return mapMaker.makeMap();
|
||||
}
|
||||
|
||||
|
@ -61,6 +69,9 @@ public class SoftFilterCache extends AbstractDoubleConcurrentMapFilterCache {
|
|||
if (maxSize != -1) {
|
||||
mapMaker.maximumSize(maxSize);
|
||||
}
|
||||
if (expire != null) {
|
||||
mapMaker.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
return mapMaker.makeMap();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@ import org.elasticsearch.common.collect.MapMaker;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.docset.DocSet;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.cache.filter.support.AbstractConcurrentMapFilterCache;
|
||||
import org.elasticsearch.index.settings.IndexSettings;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* A weak reference based filter cache that has weak keys on the <tt>IndexReader</tt>.
|
||||
|
@ -39,9 +41,12 @@ public class WeakFilterCache extends AbstractConcurrentMapFilterCache {
|
|||
|
||||
private final int maxSize;
|
||||
|
||||
private final TimeValue expire;
|
||||
|
||||
@Inject public WeakFilterCache(Index index, @IndexSettings Settings indexSettings) {
|
||||
super(index, indexSettings);
|
||||
this.maxSize = componentSettings.getAsInt("max_size", -1);
|
||||
this.expire = componentSettings.getAsTime("expire", null);
|
||||
}
|
||||
|
||||
@Override protected ConcurrentMap<Filter, DocSet> buildFilterMap() {
|
||||
|
@ -51,6 +56,9 @@ public class WeakFilterCache extends AbstractConcurrentMapFilterCache {
|
|||
if (maxSize != -1) {
|
||||
mapMaker.maximumSize(maxSize);
|
||||
}
|
||||
if (expire != null) {
|
||||
mapMaker.expireAfterAccess(expire.nanos(), TimeUnit.NANOSECONDS);
|
||||
}
|
||||
return mapMaker.makeMap();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue