Instead of caching indexSearcher, I now cache IndexReader. If the IndexReader is already in the cache, I check if it is updated. Otherwise, I open it and pass this instance to the indexSearcher constructor.
Does this logic / code mean an optimized search query response if multiple requests go to the web server for search?
Thanks for reading.
string key = MyConstants.CacheKey.IndexReader; indexReader = MyCacheManager.Get<IndexReader>(key); if (indexReader == null)//cache is empty.open indexreader { indexReader = IndexReader.Open(myIndexFolderPath); MyCacheManager.Add(key, indexReader); indexSearcher = new IndexSearcher(indexReader); } else//cache contains indexreader...check if it is up to date { indexSearcher = base.GetIndexSearcher(myIndexFolderPath, indexReader); } protected IndexSearcher GetIndexSearcher(string indexFolderPath, IndexReader indexReader) { IndexSearcher indexSearcher = null; if (!indexReader.IsCurrent())//index is not up to date { indexReader = IndexReader.Open(indexFolderPath); indexSearcher = new IndexSearcher(indexReader); } else { indexSearcher = new IndexSearcher(indexReader); } return indexSearcher; }
Steve chapman
source share