简体   繁体   English

使ASP.NET中的缓存对象无效

[英]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. myDataSet是数据库中SELECT的结果。 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. 我没有运气尝试过iisreset

如果重新保存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). 如果您不能更改代码,该解决方案将变得有些脏(干净的方法是使用SqlCacheDependency)。

Can you change the Global.asax.cs (although it's source code as well)? 您可以更改Global.asax.cs吗(尽管它也是源代码)? You can access the HttpContext from here and empty the cache in your code. 您可以从此处访问HttpContext并清空代码中的缓存。

iisreset should work. iisreset应该起作用。 Whenever the ASP.Net application is unloaded from memory it will clear out any server managed Session data. 每当从内存中卸载ASP.Net应用程序时,它将清除所有服务器管理的Session数据。 Even just touching the web.config should unload the app. 即使只是触摸web.config也应卸载该应用程序。

iisreset did work! iisreset确实起作用了! I did'nt notice the changes as the IE was caching the datasets. 当IE缓存数据集时,我没有注意到更改。 So, the original question is not fully accurate. 因此,原始问题并不完全准确。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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