Question

We'll be populating the cache ahead of time, rather than on-demand, and it would help to have an efficient ContainsKey-equivalent that only tests whether the specific key is stored, without the overheads of serialization/deserialization and pulling the content over the wire that come from Get(key) != null.

Bizarrely, I can't find anything in the API to achieve this. Does anyone know of a workaround? Tags aren't really an option, since they'd require named regions, and we really need the resilence of a distributed cache.

Was it helpful?

Solution

Unfornately, there is no method to do this in Windows Server AppFabric (neither in Azure Cache).

The best you can do is an extension method like this one

public static bool Contains(this DataCache dataCache, string key)
{
    return dataCache.Get(key) != null;
}

You have to pay the Serialization Tax which can be problematic. It depends on you context.

The only workaround I know is by using regions : CreateRegion returns false if the region already exists. Never tested how it scales, but I don't think so.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top