开发者

Can ASP.Net Caching be used inside an MVC Controller?

开发者 https://www.devze.com 2023-02-17 00:16 出处:网络
If so how do I get a hold of the Cache object? 开发者_JAVA百科I tried declaring a static Cache object in my controller (hoping it will not be disposed too frequently) like so:

If so how do I get a hold of the Cache object?

开发者_JAVA百科I tried declaring a static Cache object in my controller (hoping it will not be disposed too frequently) like so:

private static readonly System.Web.Caching.Cache cache = new System.Web.Caching.Cache();

As soon as I call cache["MyObject"] I get a nullReference at System.Web.Caching.Cache.Get(String key) (did the old ASP.Net Page class catch that? yuck!)

I need caching with a file dependency.


You should not create a brand new Cache object, you need to retrive it from HttpContext like this: HttpContext.Cache

0

精彩评论

暂无评论...
验证码 换一张
取 消