Package org.hibernate
Enum Class CacheMode
- All Implemented Interfaces:
FindOption,Serializable,Comparable<CacheMode>,Constable
Controls how the session interacts with thesecond-level cache orquery cache. An instance of
CacheMode may be viewed as packaging a JPA-definedCacheStoreMode with aCacheRetrieveMode. For example,PUT represents the combination(BYPASS, USE). However, this enumeration recognizes only five such combinations. In Hibernate,CacheStoreMode.REFRESH always impliesCacheRetrieveMode.BYPASS, so there's noCacheMode representing the combination(REFRESH, USE).
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extendsEnum<E>>Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe session may read items from the cache, but will not add items, except to invalidate items when updates occur.The session will never interact with the cache, except to invalidate cached items when updates occur.The session may read items from the cache, and add items to the cache as it reads them from the database.The session will never read items from the cache, but will add items to the cache as it reads them from the database.As with toPUT, the session will never read items from the cache, but will add items to the cache as it reads them from the database.Method Summary
Modifier and TypeMethodDescriptionstaticCacheModefromJpaModes(CacheRetrieveMode retrieveMode,CacheStoreMode storeMode) Interpret the given JPA modes as an instance of this enumeration.staticCacheModeinterpretExternalSetting(String setting) Interpret externalized form as an instance of this enumeration.booleanDoes this cache mode indicate that reads are allowed?booleanDoes this cache mode indicate that writes are allowed?staticCacheModeReturns the enum constant of this class with the specified name.staticCacheMode[]values()Returns an array containing the constants of this enum class, inthe order they are declared.
Enum Constant Details
NORMAL
The session may read items from the cache, and add items to the cache as it reads them from the database.IGNORE
The session will never interact with the cache, except to invalidate cached items when updates occur.GET
The session may read items from the cache, but will not add items, except to invalidate items when updates occur.PUT
The session will never read items from the cache, but will add items to the cache as it reads them from the database. In this mode, the value of the configuration setting"hibernate.cache.use_minimal_puts" determines whether an item is written to the cache when the cache already contains an entry with the same key. Minimal puts should be:- disabled for a cache where writes and reads carry a similar cost, as is usually the case for a local in-memory cache, and
- enabled for a cache where writes are much more expensive than reads, which is usually the case for a distributed cache.
It's not usually necessary to specify this setting explicitly because, by default, it's set to a sensible value by the second-level cache implementation.
REFRESH
As with toPUT, the session will never read items from the cache, but will add items to the cache as it reads them from the database. But in this mode, the effect of the configuration setting"hibernate.cache.use_minimal_puts" is bypassed, in order toforce a refresh of a cached item, even when an entry with the same key already exists in the cache.
Method Details
values
Returns an array containing the constants of this enum class, inthe order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
valueOf
Returns the enum constant of this class with the specified name.The string must matchexactly an identifier used to declare anenum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
getJpaStoreMode
- Returns:
- the JPA-defined
CacheStoreModeimplied by this cache mode
getJpaRetrieveMode
- Returns:
- the JPA-defined
CacheRetrieveModeimplied by this cache mode
isGetEnabled
public boolean isGetEnabled()Does this cache mode indicate that reads are allowed?- Returns:
trueif cache reads are allowed;falseotherwise.
isPutEnabled
public boolean isPutEnabled()Does this cache mode indicate that writes are allowed?- Returns:
trueif cache writes are allowed;falseotherwise.
interpretExternalSetting
Interpret externalized form as an instance of this enumeration.- Parameters:
setting- The externalized form.- Returns:
- The matching enum value.
- Throws:
MappingException- Indicates the external form was not recognized as a valid enum value.
fromJpaModes
Interpret the given JPA modes as an instance of this enumeration.