ICacheItemExpiration.Initialize - what is it for?

Topics: Caching Application Block
Feb 17, 2009 at 6:22 PM

The ICacheItemExpiration has a method Initialize, HasExpired and Notify.
I get the HasExpired and Notify, but what does the Initialize good for?

Feb 18, 2009 at 2:25 AM
Taken from the documentation - "Called to give the instance the opportunity to initialize itself from information contained in the CacheItem. "
In the source code, it was only actually used for cache items which uses the SlidingTime expiration policy. This is to get the time the item was last used which also includes the time it was created that's why you'll notice it is also being called in the constructor.  This is necessary since SlidingTime compares the time the item was last accessed to the  current datetime to determine if it has already expired.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Feb 18, 2009 at 9:40 AM
Edited Feb 18, 2009 at 9:48 AM

I have ran a few examples and it seems that if the application crashes while data is being persisted in a backing store - when it reloads the HasExpired method is being called before the Initialize method.

I'll explain what i want - it seems that the cache manager expired my objects when the application loads after a crash, i want to disable this and if this is the situation - let the sliding time reset itself.

Of course i'm using a home made expiration item implementing the ICacheItemExpiration in which i am using my own SlidingTime object, and when the ICacheItemExpiration.Notify is being called i am notifying the SlidingTime object. I'm doing this since i have to save the item to an operational database before it is being removed from cache - this feature is not available in the build in expireres.
How would i know if the item has just been loaded from the backing store after a crash?

I though about using a flag to indicate if this is the first time the item is being checked for expiration - but it won't work since this flag will be stored with all the other information in the backing store.

Any ideas?


Feb 19, 2009 at 10:58 AM

Can you provide us with some code snippets for your implemetation if ICacheItemExpiration? and also how can we simulate that the application crashes and on the reload the cached items is expired? Can you provide us steps for this? 

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.