org.eclipse.persistence.annotations
Annotation Type Cache

@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Cache

The Cache annotation is used to configure the EclipseLink object cache.
By default EclipseLink uses a shared object cache to cache all objects.
The caching type and options can be configured on a per class basis to allow
optimal caching.

This includes options for configuring the type of caching,
setting the size, disabling the shared cache, expiring objects, refreshing,
and cache coordination (clustering).

A Cache annotation may be defined on an Entity or MappedSuperclass. In the
case of inheritance, a Cache annotation should only be defined on the root
of the inheritance hierarchy.

refreshOnlyIfNewer
(Optional) For all queries that go to the database, refresh the cache
only if the data received from the database by a query is newer than
the data in the cache (as determined by the optimistic locking field).

boolean

shared
(Optional) Cached instances in the shared cache,
or only a per EntityManager isolated cache.

size

shared

public abstract boolean shared

(Optional) Cached instances in the shared cache,
or only a per EntityManager isolated cache.
The default is shared.

Default:

true

expiry

public abstract int expiry

(Optional) Expire cached instance after a fix period of time (ms).
Queries executed against the cache after this will be forced back
to the database for a refreshed copy.
By default there is no expiry.

expiryTimeOfDay

(Optional) Expire cached instance a specific time of day. Queries
executed against the cache after this will be forced back to the
database for a refreshed copy.

Default:

@org.eclipse.persistence.annotations.TimeOfDay(specified=false)

alwaysRefresh

public abstract boolean alwaysRefresh

(Optional) Force all queries that go to the database to always
refresh the cache.
Default is false.
Consider disabling the shared cache instead of forcing refreshing.

Default:

false

refreshOnlyIfNewer

public abstract boolean refreshOnlyIfNewer

(Optional) For all queries that go to the database, refresh the cache
only if the data received from the database by a query is newer than
the data in the cache (as determined by the optimistic locking field).
This is normally used in conjunction with alwaysRefresh, and by itself
it only affect explicit refresh calls or queries.
Default is false.

Default:

false

disableHits

public abstract boolean disableHits

(Optional) Setting to true will force all queries to bypass the
cache for hits but still resolve against the cache for identity.
This forces all queries to hit the database.