Search code examples
azureazure-caching

Azure DataCaches and regions


I understand that regions in Azure caches provide a different way to access objects in the cache (other than using the key).

However, I'm wondering why there is a version of DataCache.GetAndLock() that accepts both the key and the region.

Isn't the key enough to identify the object in the cache? Or can I have objects with the same key in the different regions (in the same DataCache)?

What happens if I add an object to a certain region and then try to get it without specifying the region (but only the key)?


Solution

  • A key defines an object within a region.

    Regions exist as a mechanism for specifying that similar data should be stored on the same cache server. This allows you to leverage the cache calls that search the cache and return a set of objects. Without the guarantee that regions provide, these queries may have to fan out to multiple cache servers.

    If you insert an object using the overload that does not specify the region, you must similarly access it using the method overloads that do not specify a region. These objects are stored in the default cache and there is no guarantee that they reside on a single cache server.

    On the contrary, if you need to use the tagging and searching options of the cache, you should be inserting your objects into a specific region and using the corresponding Get operations that specify a region as well.