在ASP.NET中使用System.Web.Caching.Cache类时出现问题 [英] Problem Using the System.Web.Caching.Cache Class in ASP.NET

查看:66
本文介绍了在ASP.NET中使用System.Web.Caching.Cache类时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在研究一个使用ASP.NET的项目。我试图调用Cache [ key],但是编译器抱怨System.Web.Caching.Cache如何在这一点上仍然有效。



如果我调用Cache obj = new Cache();

我可以访问HttpContext.Current.Cache-但这不能让我在Insert()方法中指定绝对到期和滑动到期。 / p>

有人可以帮我吗?

解决方案

您应该可以或滑动过期,在HttpRuntime.Cache上调用insert。它有几个重载。例如:

  HttpRuntime.Cache.Insert( EXAMPLE_KEY,
exampleItem,
Nothing,
DateTime.Now.AddHours(1),
System.Web.Caching.Cache.NoSlidingExpiration);

完全相同的代码也应与HttpContext.Current.Cache一起使用。


So I am working on a project which uses ASP.NET. I am trying to call Cache["key"] but the compiler complains about how System.Web.Caching.Cache is "nat valid at this point".

If I call Cache obj = new Cache(); the obj is always null.

I can access HttpContext.Current.Cache - but this doesnt let me specify an absolute expiration and sliding expiration in the Insert() method.

Can someone help me?

解决方案

You should be able to absolute or sliding expiration calling the insert on HttpRuntime.Cache. It has several overloads. Ex:

HttpRuntime.Cache.Insert("EXAMPLE_KEY", 
                        exampleItem, 
                        Nothing,                           
                        DateTime.Now.AddHours(1),
                        System.Web.Caching.Cache.NoSlidingExpiration);

The exact same code should also work with HttpContext.Current.Cache.

这篇关于在ASP.NET中使用System.Web.Caching.Cache类时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆