HttpRuntime.Cache在哪里存储数据? [英] Where does HttpRuntime.Cache stores data?

查看:159
本文介绍了HttpRuntime.Cache在哪里存储数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现具有缓存功能的Web应用程序.我需要缓存的原因是因为我们有一个允许用户访问在线课程的应用程序.现在,一旦用户登录,我就可以根据我们的数据库对其进行验证.验证之后,我想将用户ID和课程ID在缓存中存储20分钟,以便他再次请求时,我可以从缓存中检索用户ID和课程ID的值,如果有效,则向他提供访问权限由于某些原因,我无法在此应用程序中使用Session变量,因此它们不是一个选择.

I am trying to implement a web application with Caching features.The reason I need caching is for is that we have an application which lets users access online courses. Now, Once the user logs in I validate him against our database. Once validated I want to store the user ID and course ID in cache for 20 mins so that if he requests it again I can retrieve values from cache foe both user id and course ID and if valid provide him access For some reasons I can't use Session variables in this application so they are not an option.

现在,我的应用程序中的缓存代码位于HTTP Handler(.ashx文件)内部.现在,我尝试像对aspx页面那样调用缓存对象,但是我做不到,可能是因为它是处理程序而不是网页.所以,

Now, the caching code in my application is inside a HTTP Handler(.ashx file). Now I tried calling the cache object like you do for a aspx page but I could not, probably because it's a handler and not a webpage. So,

Cache.Insert("Id", 123); 

在Handler中不起作用.因此,我尝试了HTTPRuntime.cache.但是经过研究后,我发现HTTPRuntime.cache对于整个应用程序是通用的.我不完全了解整个应用程序".这是否意味着它由访问我们应用程序的不同计算机上的所有用户共享?还是意味着它被访问我们的应用程序的一台计算机上的所有用户共享.因为如果是后者,我可以接受.那么HTTPRuntime.cache是​​一种为一台浏览器(或一台计算机)缓存数据的好方法,还是有另一种更好的方法来实现浏览器缓存来存储数据?

will not work in Handler. So then I tried HTTPRuntime.cache. But after doing some research I found out the HTTPRuntime.cache is common to the whole application. I don't completely understand "Whole application". Does it mean that it is shared by all the users on different computers accessing our applications? or does it mean it's shared by all the users on one computer accessing our application. Because if it is the latter I am OK with it. So is HTTPRuntime.cache a good way to cache data for one browser(or one computer) or is there a different and better way to implement Browser caching to store data?

推荐答案

缓存存储在Web服务器内存中.

Cache is stored in web server memory.

您应该了解 Viewstate,缓存和会话之间的区别

这篇关于HttpRuntime.Cache在哪里存储数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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