简体   繁体   中英

Invalidating a cache object in ASP.NET

I am maintaining an application in which the developer has used data caching in the following manner:

HttpContext.Current.Cache["key"] = myDataSet;

He hasn't specified when this cache gets invalidated. The myDataSet is a result of a SELECT from the database. The database was updated, but the cache is not invalidated. I do not want to change the source code. I simply want to invalidate it. I tried iisreset with no luck.

如果重新保存web.config ,则与iisreset相比,应用程序池将更优雅地回收,缓存的结果相同。

The solution is going to be somewhat dirty anyway if you can't change the code (the clean way would be to use SqlCacheDependency).

Can you change the Global.asax.cs (although it's source code as well)? You can access the HttpContext from here and empty the cache in your code.

iisreset should work. Whenever the ASP.Net application is unloaded from memory it will clear out any server managed Session data. Even just touching the web.config should unload the app.

iisreset did work! I did'nt notice the changes as the IE was caching the datasets. So, the original question is not fully accurate.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM