开发者

CachingCallHandler no way to invalidate cache object?

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 r开发者_如何学JAVAemove 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜