5

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.

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); 

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?

Abhi.Net
  • 722
  • 3
  • 11
  • 37
  • Caching and SessionState are 2 completely different things. You can't use them interchangeably. It sounds like you are looking for a persistent sessionstate. Normally one would just save that data in the db. – leppie Jun 04 '12 at 05:56
  • I am not using them interchangeably. I am trying to implement a cache solution to store User data for 20 minutes. All i want to know is if HTTPRuntime.Cache browser(or computer specific) or is common to all the users of the application working on different computers – Abhi.Net Jun 04 '12 at 05:58

1 Answers1

6

Cache is stored in web server memory.

You should understand the differences between Viewstate, Cache and Session

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
Nikhil D
  • 2,479
  • 3
  • 21
  • 41
  • Thank you for your prompt reply, I went through the document and it clearly states the difference between Session state and Cache. But what about Browser cache? Can't I store user information in Browser cache? So that it is shared by multiple users but on a single computer(Or browser). – Abhi.Net Jun 04 '12 at 06:14
  • @Abhi.Net define "user" in that sentence... if you mean "user account" (for example, a domain user), then no: their data is intentionally separate. If you mean people are logging in/out of your *application* then there may be some things possible via "localstorage". But that is then a javascript question. – Marc Gravell Jun 04 '12 at 06:23
  • User does mean "User account" in my case. Implementing it through JavaScript is out of question.What do you mean by "their data is intentionally separate"? from what I am gathering is that I cannot store user information in Browser cache through .NET code? am i right? If so what would you suggest be the best possible way to achieve what I am trying.Sessions, cookies....? – Abhi.Net Jun 04 '12 at 06:30