Memcached: Update Notification for Client Caches
Let's take the .NET client of Memcached for example:
As we know, if we want to put some data to the cache server, we call some API like Cache.Add(string key, object data)
, and the memeched client will serialize the data
and then send it to the cache servers. If the data
is a complex object (has a large object graph), the serialization process might be very slow. So, I try to use 2-level cache: Distributed Cache and In-Memory Cache.
The application code will always ask the In-Memory Cache for the cached data. If the In-Memory Cache does not have the cached data, it will then ask the cache servers for the cach开发者_开发技巧ed data. The performace can benifit from the usage of In-Memory cache, for In-Memory cache need no serialization operation and is much closer to the application.
However, there's a synchronization problem. If one web server modifies the data, it will update the database, its In-Memory Cache and the Distributed Cache. But other web servers won't be notified about this "update" event, so their In-Memory Cache won't be updated.
So the question is: How can other web servers be notified when one web server updates the data (so that they can update their In-Memory Caches)? Thanks!
BTW: I want to synchronize the cached data in a "Push Sync" fashion, that is, the cached data will be updated only when they're changed. Because in my application, there are lots of reads while only some writes.
精彩评论