Henryk
Henryk

Reputation: 1139

Determine when application cache item will timeout?

In ASP.NET, when storing a value in the application cache with absolute expiry is there a method to retrieve the date/time when the item will expire? The application cache item will be refreshed if expired based on user requests.

Upvotes: 0

Views: 1506

Answers (3)

ballpointpeon
ballpointpeon

Reputation: 204

use the CacheItemRemovedCallback; your object may get kicked from the cache earlier than you expect anyway

Upvotes: 0

Pinpin
Pinpin

Reputation: 120

There is a method signature on the HttContext.Cache object which allows you to specify a method to be called in the event that a Cached item is removed when you set a new Cache item.

Define yourself a method that'll allow you to process that information, whether you want it to re-submit the item to the Applcation Cache, email you about it, log it in the Event Log, whatever suits your needs.

Hope that helps, Pascal

Upvotes: 4

Mats
Mats

Reputation: 14817

Not sure if I've understood your question right, but I'll give it a try: I believe there is no way to actually figure out, when a certain cache-item is going to expire. In most scenarios, I use a delegate passed in as a parameter (CacheItemRemovedCallback) when adding objects to the cache, so I get notified when the item gets kicked out.

Hope this helps a bit.

Upvotes: 1

Related Questions