Apache Lucene open-source search software
LUCENE-6784: IndexSearcher's query caching is enabled by default.
Adrien Granddb6083e2557d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 55fd6e4726e..89e86dc6e20 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -181,6 +181,9 @@ Changes in Runtime Behaviorremoves the collector that threw this exception from the list of subcollectors to collect. (Adrien Grand)+* LUCENE-6784: IndexSearcher's query caching is enabled by default. Run+ indexSearcher.setQueryCache(null) to disable. (Adrien Grand)+======================= Lucene 5.3.0 =======================New Featuresdiff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.javaindex 9e3082a1d7d..b9589dfd423 100644--- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java+++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java@@ -125,9 +125,14 @@ public class IndexSearcher {};- // disabled by default- private static QueryCache DEFAULT_QUERY_CACHE = null;+ private static QueryCache DEFAULT_QUERY_CACHE;private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();+ static {+ final int maxCachedQueries = 1000;+ // min of 32MB or 5% of the heap size+ final long maxRamBytesUsed = Math.min(1L << 25, Runtime.getRuntime().maxMemory() / 20);+ DEFAULT_QUERY_CACHE = new LRUQueryCache(maxCachedQueries, maxRamBytesUsed);+ }final IndexReader reader; // package private for testing!