diff --git a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs index 3e68f0a121..c44a7cb648 100644 --- a/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs +++ b/src/Lucene.Net.Facet/Taxonomy/Directory/DirectoryTaxonomyReader.cs @@ -66,6 +66,9 @@ private class Int32Class // TODO: test DoubleBarrelLRUCache and consider using it instead private LRUHashMap ordinalCache; private LRUHashMap categoryCache; + + // Disable cache + public bool CacheDisabled { get; set; } private volatile TaxonomyIndexArrays taxoArrays; @@ -85,7 +88,7 @@ private DirectoryTaxonomyReader(DirectoryReader indexReader, DirectoryTaxonomyWr // use the same instance of the cache, note the protective code in getOrdinal and getPath this.ordinalCache = ordinalCache ?? new LRUHashMap(DEFAULT_CACHE_VALUE); this.categoryCache = categoryCache ?? new LRUHashMap(DEFAULT_CACHE_VALUE); - + this.CacheDisabled = false; this.taxoArrays = taxoArrays != null ? new TaxonomyIndexArrays(indexReader, taxoArrays) : null; } @@ -106,6 +109,7 @@ public DirectoryTaxonomyReader(Directory directory) ordinalCache = new LRUHashMap(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap(DEFAULT_CACHE_VALUE); + CacheDisabled = false; } /// @@ -126,6 +130,7 @@ public DirectoryTaxonomyReader(DirectoryTaxonomyWriter taxoWriter) ordinalCache = new LRUHashMap(DEFAULT_CACHE_VALUE); categoryCache = new LRUHashMap(DEFAULT_CACHE_VALUE); + CacheDisabled = false; } private void InitTaxoArrays() @@ -332,7 +337,8 @@ public override int GetOrdinal(FacetLabel cp) // LUCENENET: Lock was removed here because the underlying cache is thread-safe, // and removing the lock seems to make the performance better. - ordinalCache.Put(cp, new Int32Class { Value = Convert.ToInt32(ret, CultureInfo.InvariantCulture) }); + if(!CacheDisabled) + ordinalCache.Put(cp, new Int32Class { Value = Convert.ToInt32(ret, CultureInfo.InvariantCulture) }); } return ret; @@ -367,7 +373,8 @@ public override FacetLabel GetPath(int ordinal) res = new FacetLabel(FacetsConfig.StringToPath(doc.Get(Consts.FULL))); // LUCENENET: Lock was removed here because the underlying cache is thread-safe, // and removing the lock seems to make the performance better. - categoryCache.Put(ordinal, res); + if(!CacheDisabled) + categoryCache.Put(ordinal, res); return res; }