Declare cache expirations declaratively in config

Topics: Caching Application Block
Oct 21, 2009 at 9:23 PM

Is it possible to specify what expiration policies to use (e.g. SlidingTime, FileDependency etc) declaratively when caching items rather than explicitly in code?

If this functionality is not available out of the box, what would be the recommended way to accomplish this?

Thank You


Oct 22, 2009 at 2:54 AM

Yes, it's not available out of the box.  I'd say you can create your own implementation of ICacheManager which just uses an instance of entlib's own CacheManager.  Have a constructor that takes a parameter of type NameValueCollection.  This parameter will be populated based on the list of items you added in the Attributes property of the Custom Cache Manager you'll be adding later in your config.  Thus, the Attributes property will be the place where you can set the type of expiration policy you want to use.  So inside your implementation of Add method, you'll be calling the Add method of CacheManager passing that expiration policy.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Oct 22, 2009 at 1:41 PM

Thank you