0

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.

Henryk
  • 1,119
  • 1
  • 10
  • 16

3 Answers3

4

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

Pinpin
  • 120
  • 3
  • 13
1

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.

Mats
  • 14,902
  • 33
  • 78
  • 110
0

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

ballpointpeon
  • 204
  • 1
  • 5