Session VS. Cache

R

Robir

When is it better to store a small amount of data (say a very small DataSet
or a couple of short string variables) in the Session vs in the Cache
object. I've had it recommended to store such things in the Cache and to
simply stay away from the Session as a general rule. But as far as I know,
storing data in the Cache puts your data at risk in that the system might
determine that the data should be purged because the system thinks it's okay
to simply because it hasn't been accessed for a while. I understand that I
can create some callback logic that will automatically re-create the data
just purged from the Cache by the system - but that's a lot of work. Am I
correct in thinking that if I store it in the Session that I don't have to
worry about the system purging it as it would if the same data were in the
Cache? If that is correct, then what's the big benefit of storing duch data
in the Cache if I have to worry about the system purging it. Doesn't the
Cache also have the same scope/lifetime as the Session?

Thoughts? Perspective? Opinions?

TIA
 
G

Guest

Someone correct me if I'm wrong but I'm pretty sure Cache is analogous to Application -- the scope is global. Is your data local the session (the current user) or to everyone in the application

If it is local to the user but you still want to use Cache you could use the sessionid as part of the key to ensure uniqueness.
 
S

Steve C. Orr [MVP, MCSD]

Session is user specific. You don't want to store your dataset there unless
every user has differing data.
If you don't want the data to get flushed, you might consider using the
Application object.
I'm pretty sure there's functionality built into the Cache object that lets
you tell it not to flush particular items or to prioritize them.
 
K

Kevin Spencer

Application Cache and Session are equally useful, both when used correctly.
Anyone that tells you not to use Session probably doesn't know how to use it
properly. The real issue is one of scope. Sessions, as Steve said, are
user-specific, and global to all pages for a given specific user.
Application Cache is global and non-user-specific. Application Cache data
can be accessed in any page or class in the Application, and by every user.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top