views:

24

answers:

1

CachingCallHandler of the enterprise library caches items using NoAbsoluteExpiration. But, I don't see a way to invalidate the cache. That one would want an item cached forever with no way to invalidate it, doesn't make any sense.

Before I implement my own invalidation method, I wanted to validate that there doesn't exist a trivial invalidation mechanism that I'm not aware of?

Update:

It looks like this is not built in. But, I think it is using the gethashcode for the key. I can probably thus remove the key for invalidation.

I am still trying to figure out why one would want sliding expiration. Of course, if one could tie the expiration to the database or a file updating with invalidation then it could be ideal. Yet, without such advanced mechanisms for cache invalidation, it seems pointless.

A: 

You wrote:

That one would want an item cached forever

But as you mention later, it is actually a sliding expiration so the items are eventually removed from the cache if they are not accessed within a certain period of time.

Unfortunately, the CachingCallHandler only uses a sliding expiration:

Here's what it does in code:

private void AddToCache(string key, object value)
{
    object[] cacheValue = new object[] { value };
    HttpRuntime.Cache.Insert(
        key,
        cacheValue,
        null,                      // No Cache Dependencies
        Cache.NoAbsoluteExpiration,
        expirationTime,            // Sliding expiration (default 5 minutes)
        CacheItemPriority.Normal, 
        null                       // No CacheItemRemovedCallback
    );
}

As for what the point of this approach is, it does seem to be a bit limited. However, it does address the scenario where you have fairly static data that doesn't need to be refreshed on demand.

Note that the CachingCallHandler has been removed from Enterprise Library 5.0 due to "un-resolvable security vulnerabilities" so you may not want to use this feature.

Tuzo
@Tuzo Thanks. Yes, I've re-written this code to use absolute expiration.
Curtis White
@Tuzo Just as a follow-up, it is possible to re-write this code by getting the community contrib library.
Curtis White
@Curtis White: The EL 5.0 Change Log says that CachingCallHandler will be in the EL contrib site ( http://entlib.codeplex.com ) but I can't find it there. If you are thinking of contributing your modifications then I would suggest creating a new Handler and submitting that.
Tuzo