Package org.hibernate
Enum CacheMode
- java.lang.Object
-
- java.lang.Enum<CacheMode>
-
- org.hibernate.CacheMode
-
- All Implemented Interfaces:
Serializable
,Comparable<CacheMode>
public enum CacheMode extends Enum<CacheMode>
Controls how the session interacts with the second-level cache or query cache. An instance ofCacheMode
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)
.
-
-
Enum Constant Summary
Enum Constants Enum Constant Description GET
The session may read items from the cache, but will not add items, except to invalidate items when updates occur.IGNORE
The session will never interact with the cache, except to invalidate cached items when updates occur.NORMAL
The session may read items from the cache, and add items to the cache as it reads them from the database.PUT
The session will never read items from the cache, but will add items to the cache as it reads them from the database.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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CacheMode
fromJpaModes(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode)
Interpret the given JPA modes as an instance of this enumeration.CacheRetrieveMode
getJpaRetrieveMode()
CacheStoreMode
getJpaStoreMode()
static CacheMode
interpretExternalSetting(String setting)
Interpret externalized form as an instance of this enumeration.boolean
isGetEnabled()
Does this cache mode indicate that reads are allowed?boolean
isPutEnabled()
Does this cache mode indicate that writes are allowed?static CacheMode
valueOf(String name)
Returns the enum constant of this type with the specified name.static CacheMode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NORMAL
public static final CacheMode NORMAL
The session may read items from the cache, and add items to the cache as it reads them from the database.
-
IGNORE
public static final CacheMode IGNORE
The session will never interact with the cache, except to invalidate cached items when updates occur.
-
GET
public static final CacheMode GET
The session may read items from the cache, but will not add items, except to invalidate items when updates occur.
-
PUT
public static final CacheMode 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
public static final CacheMode 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 Detail
-
values
public static CacheMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (CacheMode c : CacheMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static CacheMode valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
-
getJpaStoreMode
public CacheStoreMode getJpaStoreMode()
- Returns:
- the JPA-defined
CacheStoreMode
implied by this cache mode
-
getJpaRetrieveMode
public CacheRetrieveMode 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
public static CacheMode interpretExternalSetting(String setting)
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
public static CacheMode fromJpaModes(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode)
Interpret the given JPA modes as an instance of this enumeration.
-
-