tags:

views:

199

answers:

1

Question about how AppFabric's cache feature can be used.

I apologize for asking a question that I should be able to answer from the documentation, but I have read and read and searched and cannot answer this question, which leads me to believe that I have a fundamentally flawed understanding of what AppFabric's caching capabilities are intended for.

I work for a geographically disperse company. We have a particular application that was originally written as a client/server application. It’s so massive and business critical that we want to baby step converting it to a better architected solution.

One of the ideas we had was to convert the app to read its data using WCF calls to a co-located web server that would cache communication with the database in the United States. The nature of the application is such that everyone will tend to be viewing the same 2000 records or so with only occasional updates and those updates will be made by a limited set of users.

I was hoping that AppFabric’s cache mechanism would allow me to set up one global cache and when a user in Asia, for example, requested data that was not in the cache or was stale that the web server would read from the database in the USA, provide the data to the user, then update the cache which would propagate that data to the other web servers so that they would know not to go back to the database themselves.

Can AppFabric work this way or should I just have the servers retrieve their own data from the database?

+2  A: 

So if I understand you right, you have:

  • a database server in the USA
  • web servers around the world?
  • (potentially) an AppFabric cache in the USA

AppFabric gives you potentially two ways to address this scenario.

  1. Local cache
    In an AppFabric setup, clients have the capability to have a local cache of objects, where the first call to the cache for an object places the object in the local cache and subsequent requests for that object are fulfilled from the local cache. Objects are removed from the local cache either due to a timeout or because the main cache notifies the local cache that the object is stale. You configure this in your web.config:

    <dataCacheClient>
        <localCache isEnabled="true" sync="NotificationBased" ttlValue="300" />
    </dataCacheClient>
    

    In your case then, your web servers are the clients; when one of your Asian users requests an object, the local cache for the Asia web server would then hold a copy of that object. Updates to that object would be propagated to the main cache, and in a notification-based setup copies of that object in local caches on the other web servers would be invalidated, so that the next request would be fulfilled from the main cache and then the local cache would be refreshed with the updated object.

  2. Colocate the AppFabric cache on the web servers
    There's nothing to stop your web servers also being AppFabric cache servers! In this setup you wouldn't use the local cache, because it doesn't make sense when the main cache is already local to your client. However, this would ensure that your client is always pulling the latest version of a cached object from the cache.
    You'd need to be careful of network loads, though, because this setup might mean your USA web server is always reading cached objects from (say) your European web server, which could slow down both your servers as they try to serve cache requests as well as web traffic.

In both cases remember that while your clients will receive the latest version of the cached object, there's no persistence in AppFabric and you'll need to write your changes to the database at the same time as you update the cached object, otherwise you run the risk of reading out-of-date data into the cache.

PhilPursglove
Phil, thanks so much for your (very detailed) response. This helps solidify so much.
Kevin Buchan