Top Description Fields Constructors Methods
org.hibernate

public final Enum CacheMode

extends Enum<CacheMode>
Class Inheritance
Imports
java.util.Locale, jakarta.persistence.CacheRetrieveMode, .CacheStoreMode

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, CacheMode#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).

Authors
Gavin King, Strong Liu
See Also
Session#setCacheMode(CacheMode), org.hibernate.query.SelectionQuery#setCacheMode(CacheMode), CacheStoreMode, CacheRetrieveMode

Field Summary

Modifier and TypeField and Description
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.

public static final CacheMode
IGNORE

The session will never interact with the cache, except to invalidate cached items when updates occur.

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.

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.

public static final CacheMode
REFRESH

As with to PUT, the session will never read items from the cache, but will add items to the cache as it reads them from the database.

private final CacheRetrieveMode
private final CacheStoreMode

Constructor Summary

AccessConstructor and Description
private
CacheMode(CacheStoreMode storeMode, CacheRetrieveMode retrieveMode)

Method Summary

Modifier and TypeMethod and Description
public static CacheMode
fromJpaModes(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode)

Interpret the given JPA modes as an instance of this enumeration.

public CacheRetrieveMode

Returns:

the JPA-defined CacheRetrieveMode implied by this cache mode
getJpaRetrieveMode
()

public CacheStoreMode

Returns:

the JPA-defined CacheStoreMode implied by this cache mode
getJpaStoreMode
()

public static CacheMode

Returns:

The matching enum value.
interpretExternalSetting
(String
The externalized form.
setting
)

Interpret externalized form as an instance of this enumeration.

public boolean

Returns:

true if cache reads are allowed; false otherwise.
isGetEnabled
()

Does this cache mode indicate that reads are allowed?

public boolean

Returns:

true if cache writes are allowed; false otherwise.
isPutEnabled
()

Does this cache mode indicate that writes are allowed?

public static CacheMode
public static CacheMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

GETback to summary
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.

IGNOREback to summary
public static final CacheMode IGNORE

The session will never interact with the cache, except to invalidate cached items when updates occur.

NORMALback to summary
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.

PUTback to summary
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.

See Also
org.hibernate.boot.SessionFactoryBuilder#applyMinimalPutsForCaching(boolean)
REFRESHback to summary
public static final CacheMode REFRESH

As with to PUT, 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.

See Also
org.hibernate.boot.SessionFactoryBuilder#applyMinimalPutsForCaching(boolean)
retrieveModeback to summary
private final CacheRetrieveMode retrieveMode
storeModeback to summary
private final CacheStoreMode storeMode

Constructor Detail

CacheModeback to summary
private CacheMode(CacheStoreMode storeMode, CacheRetrieveMode retrieveMode)

Method Detail

fromJpaModesback to summary
public static CacheMode fromJpaModes(CacheRetrieveMode retrieveMode, CacheStoreMode storeMode)

Interpret the given JPA modes as an instance of this enumeration.

getJpaRetrieveModeback to summary
public CacheRetrieveMode getJpaRetrieveMode()
Returns:CacheRetrieveMode

the JPA-defined CacheRetrieveMode implied by this cache mode

getJpaStoreModeback to summary
public CacheStoreMode getJpaStoreMode()
Returns:CacheStoreMode

the JPA-defined CacheStoreMode implied by this cache mode

interpretExternalSettingback to summary
public static CacheMode interpretExternalSetting(String setting)

Interpret externalized form as an instance of this enumeration.

Parameters
setting:String

The externalized form.

Returns:CacheMode

The matching enum value.

Exceptions
MappingException:
Indicates the external form was not recognized as a valid enum value.
isGetEnabledback to summary
public boolean isGetEnabled()

Does this cache mode indicate that reads are allowed?

Returns:boolean

true if cache reads are allowed; false otherwise.

isPutEnabledback to summary
public boolean isPutEnabled()

Does this cache mode indicate that writes are allowed?

Returns:boolean

true if cache writes are allowed; false otherwise.

valueOfback to summary
public static CacheMode valueOf(String name)
valuesback to summary
public static CacheMode[] values()