CacheStoreMode USE和REFRESH之间有什么区别 [英] What is the difference between CacheStoreMode USE and REFRESH

查看:191
本文介绍了CacheStoreMode USE和REFRESH之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CacheStoreMode 的javadoc在某一点上有所区别我无法理解:

The javadocs for CacheStoreMode differentiate in a point I cannot really grasp:

USE 模式的javadoc:

The javadocs for the USE mode:


从数据库读取时以及将
提交到数据库时,将实体数据插入/更新到缓存中:这是默认行为。从数据库读取时不强制
刷新已缓存的项目。

Insert/update entity data into cache when read from database and when committed into database: this is the default behavior. Does not force refresh of already cached items when reading from database.

的javadocs REFRESH 模式在最后一句中有所不同:

The javadocs for the REFRESH mode differ in the last sentence:


强制刷新从数据库读取的项目的缓存。

Forces refresh of cache for items read from database.

当从数据库读取时更新现有的缓存实体实例时,这通常涉及覆盖现有数据。那么在这种情况下强制和不强制刷新之间的区别是什么?

When an existing cached entity instance is updated when reading from database, this would typically involve overwriting the existing data. So what is the difference between forcing and not forcing a refresh in this context?

谢谢。

推荐答案

据我所知:


    如果给定的EntityManagerFactory具有对底层数据库的独占写访问权,则应使用
  • CacheStoreMode.USE ,这意味着实体实例不可能存储在共享缓存是陈旧的。

  • 如果底层数据库可能是,则应启用CacheStoreMode.REFRESH 由多个commiters(即EntityManagerFactory实例,不同JVM中的应用程序,外部JDBC源)访问,因此存储在共享缓存中的实体实例可能变得陈旧。

  • CacheStoreMode.USE should be used if a given EntityManagerFactory has an exclusive write-access to the underlying database thus it implies that there is no chance for an entity instance stored in the shared cache to be stale.
  • CacheStoreMode.REFRESH should be enabled if the underlying database might be accessed by multiple commiters (i.e. EntityManagerFactory instances, applications in different JVMs, external JDBC sources) thus an entity instance stored in the shared cache may become stale.

由于CacheStoreMode.USE在从数据库读取时不强制刷新已缓存的实体,因此CacheStoreMode.REFRESH会这样做。

Since CacheStoreMode.USE does not force refresh of already cached entities when reading from the database, CacheStoreMode.REFRESH does.

这篇关于CacheStoreMode USE和REFRESH之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆