Problem using same instance of indexSearcher for multiple requests

后端 未结 7 988
半阙折子戏
半阙折子戏 2020-11-30 14:47

Am using Lucene API in a .net web application. I want to use the same instance of Indexsearcher for all the requests.Hence am storing indexsearcher instance in http cache.<

7条回答
  •  旧时难觅i
    2020-11-30 15:22

    First of all it's not safe at all, it should be:

    var searcher = (IndexSearcher)HttpRuntime.Cache["IndexSearcher"];
    if(searcher == null)
    {
         searcher = new IndexSearcher(jobIndexFolderPath);
         HttpRuntime.Cache["IndexSearcher"] = searcher;
    }
    

    In your code cache can expire between check and assignment

提交回复
热议问题