开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜