Memcached:客户端缓存更新通知
让我们以Memcached的.NET客户端为例:
众所周知,如果我们想将一些数据放入缓存服务器,我们会调用一些API,例如Cache.Add(string key, object data)
, memeched 客户端将序列化数据
,然后将其发送到缓存服务器。如果数据
是一个复杂的对象(有一个大的对象图),序列化过程可能会非常慢。因此,我尝试使用两级缓存:分布式缓存和内存缓存。
应用程序代码将始终向内存缓存询问缓存的数据。如果内存缓存没有缓存数据,则会向缓存服务器请求缓存数据。使用内存缓存可以提高性能,因为内存缓存不需要序列化操作,并且更接近应用程序。
但是,存在同步问题。如果一台 Web 服务器修改了数据,它将更新数据库、内存缓存和分布式缓存。 但是其他 Web 服务器不会收到有关此“更新”事件的通知,因此它们的内存缓存也不会更新。
因此问题是:如何通知其他 Web 服务器当一台 Web 服务器更新数据(以便它们可以更新其内存缓存)时? 谢谢!
顺便说一句:我想以“推送同步”方式同步缓存数据,即缓存数据仅在更新时才会更新变了。因为在我的应用程序中,有很多读取,而只有一些写入。
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 cached 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论