Caching Expiration Policy Behavior

Topics: Caching Application Block
May 11, 2011 at 12:30 AM

One thing that is not apparent to me given the documentation is do you have to provide a new instance of an expiration policy object for EACH item added?  Given that it's a policy and not a tracker, I would think not.  However, if you use a SlidingTime policy it tracks a last used DateTime.  This makes me think that if I add two object using that same instance, then they'll expire/mark last used in tandem.  Policy is a really bad name for that concept if this is the case.  Can anyone confirm?

May 11, 2011 at 5:08 AM
Edited May 11, 2011 at 7:44 AM

Hi,

I can say not necessarily. In case that you need to mark multiple objects as expired at the same time based on the same CacheItemExpiration, you can use the same instance for those objects. So your thought is correct.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 11, 2011 at 3:07 PM

What I'm trying to do is pass a single policy to a repistory class and every time I do GetObject(), I check if it's in the cache.  If not I add it with the same expiration policy.  Given the name, it was not apparent that a policy is actually a lifetime tracker.  So using the same instance will not work as I want them to expire at different times.  So now I have to devise a way of building a new policy for object added to the cache.  Seems very strange 

May 12, 2011 at 3:43 AM

Yes, it will track the lifetime of each object in the cache. Since you want them to expire at different times, then same expiration policy instance will not work here. I'm not sure of why you wanted to have a single policy, but instantiating a new expiration policy for each object is the simplest way I can see here.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com