Apache Lucene open-source search software
Disable the query cache by default. (#14187)
Adrien Grand26387b4b00e3
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 74048906a71..fd3f1596b06 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -43,6 +43,10 @@ Bug Fixes* GITHUB#14075: Remove duplicate and add missing entry on brazilian portuguese stopwords list. (Arthur Caccavo)+Changes in Runtime Behavior+---------------------+* GITHUB#14187: The query cache is now disabled by default. (Adrien Grand)+Other---------------------diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.mdindex 62a30c2444c..385ed64ae4b 100644--- a/lucene/MIGRATE.md+++ b/lucene/MIGRATE.md@@ -24,6 +24,17 @@This parameter has no replacement, TieredMergePolicy no longer bounds thenumber of segments that may be merged together.+### Query caching is now disabled by default++Query caching is now disabled by default. To enable caching back, do something+like below in a static initialization block:++```+int maxCachedQueries = 1_000;+long maxRamBytesUsed = 50 * 1024 * 1024; // 50MB+IndexSearcher.setDefaultQueryCache(new LRUQueryCache(maxCachedQueries, maxRamBytesUsed));+```+## Migration from Lucene 9.x to Lucene 10.0### DataInput#readVLong() may now read negative vlongsdiff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.javaindex 9359b05224a..71d72d68214 100644--- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java+++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java@@ -79,8 +79,9 @@ public class IndexSearcher {@SuppressWarnings("NonFinalStaticField")static int maxClauseCount = 1024;+ // Caching is disabled by default.@SuppressWarnings("NonFinalStaticField")- private static QueryCache DEFAULT_QUERY_CACHE;+ private static QueryCache DEFAULT_QUERY_CACHE = null;@SuppressWarnings("NonFinalStaticField")private static QueryCachingPolicy DEFAULT_CACHING_POLICY = new UsageTrackingQueryCachingPolicy();@@ -92,13 +93,6 @@ public class IndexSearcher {// shouldn't hurt either.private volatile boolean partialResult = false;- 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);- }-/*** By default, we count hits accurately up to 1000. This makes sure that we don't spend most time* on computing hit counts