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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top