我正在尝试使用缓存,但在下面得到错误。我如何正确地使用缓存?
protected void Page_Load(object sender, EventArgs e) {
x = System.DateTime.Now.ToString();
if (Cache["ModifiedOn"] == null) { // first time so no key/value in Cache
Cache.Insert("ModifiedOn", x); // inserts the key/value pair "Modified On", x
}
else { // Key/value pair already exists in the cache
x = Cache["ModifiedOn"].ToString();
} }'System.Web.Caching.Cache‘是'type’,但使用起来像‘变量’
发布于 2011-07-22 14:53:06
System.Web.Caching.Cache:这是.NET缓存的实现。
System.Web.HttpContext.Current.Cache:这是该实现的实例,它位于应用程序域中。
如果您不在aspx页面后面的代码中,我认为您希望使用第二个页面。如果您在aspx页面后面的代码中,请使用缓存。
您还可以通过页面对象直接使用具有对Page.Cache.Insert的引用的System.Caching.Cache。所有这些都指向对所有用户都是全局的同一个应用程序缓存。
发布于 2016-03-15 00:02:42
类在被new初始化时存储HttpContext的某个位置,或者使用Init()方法。
然后使用HttpContext.Current.Cache
或:使用参数currentcache创建读取和写入缓存的方法,并在用HttpContext.Current.Cache调用缓存的示例代码中对此进行记录。
https://stackoverflow.com/questions/6791681
复制相似问题