• Windows Azure Caching Service: How distributed and local caches work together

    Published by Jorge Rowies on January 17th, 2012 11:12 am under Cache, Caching Services, Windows Azure

    No Comments

    Introduction

    The intention of this post is to show how the distributed and local cache of the Windows Azure Caching Service work together. We are going to cover the implications of enabling the local cache feature, the interaction between the local and distributed caches, and how to prevent unexpected errors that can be caused by the in-memory nature of the local cache.

    For a complete description about what the Windows Azure Caching Service is and how it can be configured, please read:
    Introducing the Windows Azure Caching Service
    Azure AppFabric Caching Service
    Building Windows Azure Applications with the Caching Service

    Implications of enabling the local cache feature

    When a client enables the local cache feature, an in-memory cache is created in the same memory space where the client is running. This dramatically improves performance when storing and retrieving cache objects, but this does not come without a cost. By enabling local cache in every client, more replicas of the same data will exist, since you will have copies of the data in the original source (i.e. SQL database), in the distributed cache (cloud) and in every client’s local cache as well. Handling data replication is not a trivial matter, so deciding whether to enable local caching or not will depend on the scenario.

    Interaction between the local and distributed caches

    One important thing to know is how local and distributed caches interact with each other. Below you can find diagrams showing how two clients (Blue and Green) perform actions against the cache, and the consequences that each action has on the data of every cache instance.

    Blue client stores key “A” in the cache:

    Green client retrieves key “A” from the cache

    Blue client retrieves key “A” from the cache

    Blue client updates value for key “A”

    Blue client removes key “A” from the cache

    Green client retrieves key “A” from the cache

    NOTE: for the use cases depicted in the diagrams, we are assuming that the objects stored in the caches will not expire before clients try to retrieve them.

    The in-memory nature of the local cache

    Given that the local cache resides in-memory, keep in mind that every change to an object after it was stored in the cache, will change the cached object as well (because the objects are the same). Clearly, this is not true with the distributed cache, because a serialized representation of the object is stored in that case.

    Storing a new Movie object in the cache:

    Changing the properties of the same Movie object will change the object stored in the local cache as well:

    That’s it, I hope this helps!

    Tags: , ,

  • Leave a comment

    Your email address will not be published.

Archives

@jrowies