数字海洋无状态服务器(我有4个在数字海洋上运行的服务器)可以与我在Spring Boot上实施的缓存政策一起使用吗?

发布于 2025-02-09 17:31:27 字数 170 浏览 2 评论 0原文

我已经在Spring Boot Rest应用程序中实现了缓存。我的政策包括基于时间的缓存驱逐策略,以及基于更新的缓存驱逐策略。我担心,由于我使用无状态服务器,如果有一种调用方法来更新某些数据,并且由服务器实例A处理,那么服务器实例B,C和D中的相应缓存也没有更新。

这是我要面对的问题 /是否有办法克服这个问题?

I have implemented Caching in my Spring Boot REST Application. My policy includes a time based cache eviction strategy, and an update-based cache eviction strategy. I am worried that since I employ a stateless server, if there is a method called to update certain data, and this was handled by server instance A, then the corresponding caches in server instance B, C and D, are not updated as well.

Is this an issue I would face / is there a way to overcome this issue?

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

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

发布评论

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

评论(1

用心笑 2025-02-16 17:31:27

这是软件开发中最古老的问题 - 当您拥有多个服务器时,缓存无效

  1. 一种处理它的方法是将缓存移出单个服务器,然后将它们移至共享的某个地方,就像另一个具有缓存条目的实例一样其他应用程序是指redis [集中式缓存]

    之类的内容

  2. 第二种方法的情况 一样执行广播消息,以便每个服务器现在知道一旦修改或删除数据就会使该条目无效 - 在这里,您会运行该消息的风险未被处理,因此在某些服务器中保留了一个陈旧的条目[s]

  3. 另一个选项是由每个服务器处理的某种写入前日志(例如kafka或redis流),因此它们将全部确定性地处理事件,并且具有相同的cache state

如果您需要更多的帮助,则具有相同的高速缓存状态LMK在此外的时间

This is the oldest problem in software development - cache invalidation when you have multiple servers

  1. One way to handle it is to move your cache out of the individual servers and move them to somewhere shared like another instance that holds the cache entries that every other app refers to or something like redis [centralized cache]

  2. Second way is to do a broadcast message so that each server now knows to invalidate the entry once the data has been modified or deleted - here you run the risk of the message not being processed and thus a stale entry is left in some server[s]

  3. Another option is to have some sort of write ahead log [like kafka or redis streams] which is processed by each server and thus they will all process the events deterministically and have the same cache state

Lmk if you need more help - we can setup some time outside of SO

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