Controling cache expiration

K

Kikoz

Hi all.

I keep my ViewState in server's cache. Works fine except when user leaves
the page opened for a long time (2 hours or so). Then if he/she tries to
post it back the server throws an exception saying that ViewState was
invalid. I suspect it has something to do with cache expiration time. Can I
control its expiration time from within my web.config? Or anyhow? Couldn't
find anything related in web or machine config files or documentation :(

Just in case: I set all ViewState cache entries with CacheItemPriority.High;
I write and read ViewState to/from the hard drive if an entry gets removed
(expires) from cache (implementing CacheItemRemovedCallback delegate) - and
it looks like it only works on my local machine, files never appear on
production server and I don't see any exception logs explaining why files
were not written to the drive; I would keep ViewState in the Session object
(I suppose it would work more reliably) but I had to create my own session
object (some of my users are scared of any kind of cookies, imagine that),
so the cache is my only choice.

Any kind of help, or related articles, or thoughts would be highly
appreciated!!
Kikoz.
 
P

Paul Glavich [MVP ASP.NET]

I assume you are defining user specific cache keys for storing the viewstate
in the cache, and also manually removing it when not required anymore. If
this is the case, ensure your code is not inadvertently removing incorrect
items (or ones that dont apply to that user).

Also, the CacheItemPriority enumeration supports a NotRemovable option to
prevent it being removed from the cache when freeing system resources.
 
G

Guest

Yes, I use user-specific cache keys for each http request (a combination of
custom session variable and requested url, to be exact). I don't remove
entries manually, leaving it to the garbage collector - Cache.Insert allows
to set expiration and call back on removal (supposedly). This is why I'm
trying to use call back to flush entry that is being removed (expired) to the
disk - to preserve the ViewState even if memory gets full. And apparently it
doesn't work. I'm afraid to set entries as NotRemovable because it's a
hosting shared environment with 2 GB memory on the server, so me and other
200+ applications that are on the same disk(s) can fill that up quickly
before entries will expire if we all would have lots of requests at the same
time.

Still looking for answer. Please help, guys :)
Kikoz.
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top