我正在使用Spring框架和Java CXF服务 .
有几个客户端访问固定的数据列表,这些数据从数据库中提取 . 由于从数据库中获取是一个昂贵的调用,并且数据库不经常更改,我认为缓存值很好 .
数据库刷新 - 每天15次,无限期
缓存刷新 - >每15分钟一次 .
通过调用DB加载缓存需要15秒 .
现在,如果通过调用DB来刷新缓存,则需要15秒 . 在这15秒内,如果客户想要访问数据, I am OK to send the previous data in cache. Application is that Stale and Outdated data can be tolerated instead of waiting for 15 secs (there is a delta function which brings data after the time cache was loaded which is very inexpensive). Is there a way in ehcache to return old data in cache while the new data is being loaded while cache is refreshing at regular interval of 15 minutes?
2 回答
Ehcache有一个RestartStore,它提供快速重启和缓存持久性选项 . RestartStore实现内存缓存的磁盘镜像 . 重新启动后,缓存中最后一个数据将自动从磁盘加载到RestartStore,从那里数据将可用于缓存 .
通过将子元素添加到缓存配置来配置磁盘上的缓存持久性 . 子元素包括两个属性:strategy和synchronousWrites .
有关更多信息Ehcache
如果使用"cache aside"模式,并且应用程序代码负责重新加载缓存数据,则在它到期之前,只要缓存保存映射,您就会准确地观察到所需的行为 .
如果使用带缓存加载器的"cache through"模式,则无法获得这样的行为,因为重新加载映射时它将锁定密钥,从而阻止其他线程同时尝试访问它 .