Package org.hibernate
Enum Class CacheMode
- All Implemented Interfaces:
FindOption
,Serializable
,Comparable<CacheMode>
,Constable
Controls how the session interacts with the second-level cache
or query cache.
An instance of
CacheMode
may be viewed as packaging a JPA-defined
CacheStoreMode
with a CacheRetrieveMode
. For example,
PUT
represents the combination (BYPASS, USE)
.
However, this enumeration recognizes only five such combinations. In Hibernate,
CacheStoreMode.REFRESH
always implies CacheRetrieveMode.BYPASS
,
so there's no CacheMode
representing the combination
(REFRESH, USE)
.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<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 TypeMethodDescriptionstatic CacheMode
fromJpaModes
(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode) Interpret the given JPA modes as an instance of this enumeration.static CacheMode
interpretExternalSetting
(String setting) Interpret externalized form as an instance of this enumeration.boolean
Does this cache mode indicate that reads are allowed?boolean
Does this cache mode indicate that writes are allowed?static CacheMode
Returns the enum constant of this class with the specified name.static CacheMode[]
values()
Returns an array containing the constants of this enum class, in the 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 to force 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, in the 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 match exactly an identifier used to declare an enum 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
CacheStoreMode
implied by this cache mode
-
getJpaRetrieveMode
- Returns:
- the JPA-defined
CacheRetrieveMode
implied by this cache mode
-
isGetEnabled
public boolean isGetEnabled()Does this cache mode indicate that reads are allowed?- Returns:
true
if cache reads are allowed;false
otherwise.
-
isPutEnabled
public boolean isPutEnabled()Does this cache mode indicate that writes are allowed?- Returns:
true
if cache writes are allowed;false
otherwise.
-
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.
-