Search code examples
.netcaching.net-4.0appfabric

.Net 4 Framework Object Caching and Tags


I had a look at .Net Framework Object Caching (System.Runtime.Caching) API and I do not see any support for attaching "tags" to cached objects.

I was looking for an API similar to that of AppFabric which can support attaching tags to cached objects and then retrieving the objects based on the tag.

Are there any publicly available libraries built on top on System.Runtime.Caching which can achieve this?


Solution

  • Having had a look at the System.Runtime.Caching namespace, I think it would be (very) difficult (though not necessarily impossible) to extend it to include tagging. If you look at the members for ObjectCache, which appears to be the base class for caches, there is no support in the methods for tags (and no forthcoming support either if you look at the .NET 4.5 preview).

    Obviously methods can be overloaded to provide for tags, but CacheItem then also needs extending to add a Tags property. I'd be concerned then that for any kind of tag-based search methods similar to the GetObjectsByTag / ByAllTags / ByAnyTag supported by AppFabric, the cache would be reduced to iterating through all the CacheItems and examining them one by one which might not have the effect on performance that you might hope for (although that said, I can see that a database-based cache might have advantages in that regard).

    There's also no support (and again, none forthcoming) in the DefaultCacheCapabilities enumeration for tags, so there's no way for an API to signal to any callers that it can use tags.