推荐缓存更新策略

发布于 2024-10-12 22:47:01 字数 177 浏览 9 评论 0原文

我们的站点最近被分成了几个较小的站点,然后分布在不同的IDC中。

其中一个站点提供用户身份验证和其他用户相关服务,其他站点通过 Web 服务访问它。

在每个远程获取数据的站点上,我们都会创建一个本地缓存,这样我们就不必每次需要用户信息时都去远程。

您建议采用什么缓存更新策略来确保数据完整性?

Our site is divided into several smaller sites recently, which are then distributed in different IDCs.

One of these sites serves user authentication and other user-related services, the other sites access it through web services.

On every site that fetches data remotely, we make a local cache so that we don't have to go remote every time user information is needed.

What cache updating strategy would you recommend to ensure data integrity?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2024-10-19 22:47:01

由于您需要接近实时的更新策略,因此您肯定需要缓存失效通知引擎。

它有2种可能的实现模型:

1.Pull
主服务器会通过通知消息拉取子服务器,例如“resourceID=34392 在您的缓存中不再有效”。
此消息应在主服务器上的每次数据更新时发送。

  1. 轮询
    每个子服务器在向用户提供缓存项之前都会向主服务器询问缓存项的有效性。
    当然,在这种情况下,主服务器应该在最后的缓存生命周期内保持对象列表的更新,并非常快速地响应“If-object-was-updated”请求。

正如您在这两种情况下看到的,您的主服务器应该在每次数据更改时触发一个事件。
在第一种情况下,此事件将通过“通知总线”传输到子服务器,在第二种情况下,此事件将存储在recently-updated-objects列表中。
因此,这两个选项都需要在主服务器上进行一些代码更改。

对我来说,第二个选项更容易实现,但这很大程度上取决于您使用的软件堆栈。

Since you need the updated-policy close to realtime, you definitely need the cache-invalidation notification engine.

There are 2 possible implementation models for it:

1.Pull
Main server pulls child-servers with notification messages like "resourceID=34392 not more valid in your cache".
This message should be sent on each data update on main server.

  1. Poll
    Each child-server ask main server about the cache item validity right before serving it to user.
    Ofcourse, in this case, main server should keep the list of objects updated during last cache-lifetime period, and respond to "If-object-was-updated" requests very quickly.

As you see in both cases, your main server should trigger an event on each data change.
In first case this event will be transferred via 'notification bus' to child server, and in second case this event will be stored in recently-updated-objects list.
So both options need some code changes on main server.

As for me the second options is much more easy to implement in common, but it`s very depends of the software stack you're using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文