Remove Things in Application State After Period?

L

lucius

I would like to remove things from Application state if they are older
than 15 minutes. How can I do that?

Thanks.
 
G

Guest

Depends how you stored them in Application State. There is nothing to stop
you from creating a little "container" class that has an object field to hold
your "thing" and a DateTime field to hold the time you stored it.

Peter
 
S

Steven Cheng[MSFT]

Hi Lucius,

For your scenario, you want to store some shared objects in the global
Application State collecction and make it be cleared after a certain
period. I think you'd better consider using the Application Cache instead
of ApplicaitonState. The Application Cache is also a global storage of
ASP.NET application and you can store and access items into it like a
dictionary. Also, you can supply a CacheDependency for each cache item so
as to control how will the cached item expired(be removed from cache
collection). e.g.

//cache and object and supply the lifetime(to expire)
Cache.Insert("item key", objectToCache, null, DateTime.MaxValue,
TimeSpan.FromSeconds(10));

#Cache.Insert Method (String, Object, CacheDependency, DateTime, TimeSpan)
http://msdn2.microsoft.com/en-us/library/4y13wyk9.aspx

Actually, the ApplicationState is provided for backward compatibility to
original classic ASP. You can use Application Cache to replace
ApplicationState in ASP.NET application.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Lucius,

Does the cache approach mentioned in last reply address the problem? If you
have any further questions, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top