Hi,
Am using Lucene in a web based application and want to reuse the same instance of Indexsearcher for all the incoming requests.
Does this logic(using C#) make sense?Please suggest.
DateTime lastWriteTime = System.IO.Directory.GetLastWriteTime(myIndexFolderPath);
if (HttpRuntime.Cache["myIndexSearcher"] == null) //Cache is empty
{
searcher = new IndexSearcher(myIndexFolderPath);
HttpRuntime.Cache.Insert("myIndexSearcher", searcher);
HttpRuntime.Cache.Insert("myIndexTimeStamp", lastWriteTime);
}
else //Cache is not empty
{
DateTime cachedDateTime = (DateTime)HttpRuntime.Cache["myIndexTimeStamp"];
if (cachedDateTime == lastWriteTime)//Cache is not yet stale
{
searcher = (IndexSearcher)HttpRuntime.Cache["myIndexSearcher"];
}
else
{
searcher = new IndexSearcher(myIndexFolderPath); //index folder is modified...update searcher
HttpRuntime.Cache.Insert("myIndexSearcher", searcher);
HttpRuntime.Cache.Insert("myIndexTimeStamp", lastWriteTime);
}
}