CachingCallHandler only uses sliding expiration??

Topics: Caching Application Block , Policy Injection Application Block
Jun 26, 2008 at 2:56 AM
Edited Jun 26, 2008 at 7:49 PM
Ok, so I was using use CachingCallHandler to cache my data.  I started testing and noticed that it seem to be doing a sliding expiration.  So I started looking at the code and saw this:

private void AddToCache(string key, object value)
        {
            object[] cacheValue = new object[] { value };
            HttpRuntime.Cache.Insert(
                key,
                cacheValue,
                null,
                Cache.NoAbsoluteExpiration,
                expirationTime,  //This will cache based on a sliding expirationTime.
                CacheItemPriority.Normal, null);
        }

So, it looks like it will only handle sliding expiration and will not let you do absolute.  I can't even inherit CacheCallHandler and override the AddToCache to do absolute and than return my inherited class in a custom attribute.

So does anyone know how I can use Policy Injection and use absolute expiration rather then sliding expiration?


Jun 26, 2008 at 2:08 PM
Hi,

Looks like you'll need a new caching call handler. If you don't care too much about design time support, you can get by with a handler class and it's corresponding attribute, using the CustomCallHandler support to configure it. Your new handler would look pretty much like the built-in one, except for a difference in the constructors (it needs one taking a NameValueCollection as its only paramenter) and of course the implementation for AddToCache.

Hope this helps,
Fernando


mastrauckas wrote:
Ok, so I was using use CachingCallHandler to cache my data.  I started testing and noticed that it seem to be doing a sliding expiration.  So I started looking at the code and saw this:

private void AddToCache(string key, object value)
        {
            object[] cacheValue = new object[] { value };
            HttpRuntime.Cache.Insert(
                key,
                cacheValue,
                null,
                Cache.NoAbsoluteExpiration,
                expirationTime,  //This will cache based on a sliding expirationTime.
                CacheItemPriority.Normal, null);
        }

So, it looks like it will only handle sliding expiration and will not let you do absolute.  I can't even inherit CacheCallHandler and override the AddToCache to do absolute and than return my inherited class in a custom attribute.

So does anyone know how I can use Policy Injection and use absolute expiration rather then sliding expiration?





Jun 26, 2008 at 10:13 PM
Edited Jun 26, 2008 at 10:13 PM
Thanks for your help.  I build it and everything works.  However, I just noticed every thread has it's own instance of the cache.  I want every thread to have the same cache. Well, I might just roll my own.