Utilisez Lucene dans une application Web et souhaitez réutiliser la même instance d'Indexsearcher pour toutes les demandes entrantes.Réutilisation de IndexSearcher
Est-ce que cette logique (utilisant C#) a du sens?
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);
}
}
Si vous indentez tous vos espaces de code 4, il aura l'air lisible. – itsadok
merci ... gardez cela à l'esprit ... –