将数据库缓存到每 5 分钟刷新一次的数组中

发布于 2024-11-18 07:14:29 字数 135 浏览 5 评论 0原文

我需要使用 Java 将数据库缓存到数组中,最好的方法是什么?

我需要这个数组每 5 分钟刷新一次,并且我需要能够查询该数组。

我希望使用两个数组和某种形式的 DAO DTO 实现。

有没有这方面的既定框架?

I need to cache a database into an array using Java, what is the best way to do this?

I need this array to refresh every 5 minutes and I need to be able to query the array.

I'm looking to use two arrays and Some form of DAO DTO implementation.

Are there any set frameworks for this?

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

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

发布评论

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

评论(2

差↓一点笑了 2024-11-25 07:14:29

让您的生活更轻松的一些关键点:

  1. 对缓存数据服务使用 单例模式
  2. 使用 <一个href="http://download.oracle.com/docs/cd/E17802_01/j2se/j2se/1.5.0/jcp/beta1/apidiffs/java/util/concurrent/ScheduledExecutor.html" rel="nofollow">已计划executor 定期刷新数据
  3. 确保刷新是原子 - 考虑使用 AtomicReference 保存数据

Some key points to make your life easier:

  1. Use the singleton pattern for your cached data serivce
  2. Use a scheduled executor to periodically refresh the data
  3. Make sure the refresh is atomic - consider using an AtomicReference to hold the data
度的依靠╰つ 2024-11-25 07:14:29

您可以使用 ehcache 来实现此目的,您需要配置 DAO DTO 实现来缓存其结果和结果。从缓存中查找结果...

可以通过配置驱逐时间(缓存被清除的时间段)来实现缓存刷新。

you can use ehcache for this, you need to configure your DAO DTO implementation to cache its results & lookup results from the cache...

you can achieve the cache refresh by configuring the eviction time (time period for the cache to be cleared).

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