java - 刷新缓存时ehCache能否返回旧的缓存值

标签 java spring caching ehcache

我正在使用 Spring 框架和 Java CXF 服务。

有多个客户端访问固定的数据列表,这些数据是从数据库中获取的。由于从数据库中获取是一个昂贵的调用并且数据库不会经常更改,所以我认为缓存值是很好的。

数据库刷新 -> 每天 15 次,时间间隔不定

缓存刷新 -> 每 15 分钟一次。

通过调用数据库加载缓存需要 15 秒。

现在,如果通过调用 DB 来刷新缓存,则需要 15 秒。在这 15 秒内,如果客户端要访问数据,我可以发送缓存中以前的数据。应用是可以容忍陈旧和过时的数据,而不是等待 15 秒(有一个 delta 函数可以在加载时间缓存后带来数据,这是非常便宜的)。 ehcache 有没有办法在加载新数据时返回缓存中的旧数据,同时缓存以 15 分钟的固定间隔刷新?

最佳答案

A consistent copy of the cache on local disk provides many possibilities for business requirements, such as working with different datasets according to time-based needs or moving datasets around to different locations. It can range from a simple key-value persistence mechanism with fast read performance, to an operational store with in-memory speeds during operation for both reads and writes.

Ehcache 有一个 RestartStore,它提供快速重启和缓存持久化选项。 RestartStore 实现了内存缓存的磁盘镜像。任何重启后,缓存中最后的数据会自动从磁盘加载到 RestartStore,然后缓存中的数据可用。

通过将子元素添加到缓存配置来配置磁盘上的缓存持久性。该子元素包括两个属性:strategy 和 synchronousWrites。

<cache>
  <persistence strategy=”localRestartable|localTempSwap|none|distributed” synchronousWrites=”false|true”/>
</cache>

更多信息Ehcache

关于java - 刷新缓存时ehCache能否返回旧的缓存值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28865960/

相关文章:

java - 打印图形顶点和边缘源/目标 - JGraphT

java - 构建具有 Spring 框架依赖项的发行版

java - Spring4配置CommonsMultipartResolver失败

ruby-on-rails - Rails caches_page :index in Wrong Location

google-chrome - 为什么 Chrome 不在更改时更新 Typescript 源文件?

java.io.IOException : Cannot run program ".\bin\catalina.bat" - CreateProcess error=2, 系统找不到指定的文件

java - 为什么使用 Android Java 在一个月中得到错误的一天?

Java Spring App 在 Tomcat+Apache2 上重定向错误的 URL

java - tomcat jdbc和spring版本兼容性

php - 新的 APCu APC 用户缓存是否在进程之间共享?