Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Cache Annotation"
(New page: ==@Cache Annotation== You can define the <tt>@Cache</tt> annotation on the following: * <tt>@Entity</tt> * <tt>@MappedSuperclass</tt> * the root of the inheritance hierarchy (if applicab...) |
|||
Line 10: | Line 10: | ||
''''' Attributes of the @Cache Annotation''''' | ''''' Attributes of the @Cache Annotation''''' | ||
− | {| class="RuleFormalWideMax" dir="ltr" title="Attributes of the @Cache Annotation" summary="This table lists the attributes of EclipseLink JPA Cache annotation" width="100%" border=" | + | {|class="RuleFormalWideMax" dir="ltr" title="Attributes of the @Cache Annotation" summary="This table lists the attributes of EclipseLink JPA Cache annotation" width="100%" border="3" frame="border" rules="all" cellpadding="3" |
|- align="left" valign="top" | |- align="left" valign="top" | ||
! id="r1c1-t19" align="left" valign="bottom" | '''Attribute''' | ! id="r1c1-t19" align="left" valign="bottom" | '''Attribute''' | ||
Line 123: | Line 123: | ||
| headers="r10c1-t19 r1c5-t19" align="left" | <br> | | headers="r10c1-t19 r1c5-t19" align="left" | <br> | ||
|} | |} | ||
+ | |||
'''''Example of @Cache Annotation ''''' | '''''Example of @Cache Annotation ''''' | ||
+ | <span id="Example_of_@Cache Annotation"></span> | ||
<source lang="java"> | <source lang="java"> | ||
... | ... |
Revision as of 14:08, 18 February 2011
@Cache Annotation
You can define the @Cache annotation on the following:
- @Entity
- @MappedSuperclass
- the root of the inheritance hierarchy (if applicable)
If you define the @Cache annotation on an inheritance subclass, the annotation will be ignored. If you define the @Cache annotation on @Embeddable EclipseLink will throw an exception.
Attributes of the @Cache Annotation
Attribute | Description | Default | Required or Optional | Override with Persistence Unit Property |
---|---|---|---|---|
type |
Set this attribute to the type (org.eclipse.persistence.annotations.CacheType enumerated type) of the cache that you will be using:
|
CacheType.SOFT_WEAK |
optional |
|
size |
Set this attribute to an int value to define the size of cache to use (number of objects). |
100 |
|
|
shared |
Indicate whether cached instances should be in the shared cache or in a client isolated cache (see Isolated Client Session Cache). This allows the shared cache (L2 cache) to be disabled.
|
true |
optional |
|
expiry |
The int value to enable the expiration of the cached instance after a fixed period of time (milliseconds). Queries executed against the cache after this will be forced back to the database for a refreshed copy. |
-1 (no expiry) |
optional |
|
expiryTimeOfDay |
Specific time of day (org.eclipse.persistence.annotations.TimeOfDay) when the cached instance will expire. Queries executed against the cache after this will be forced back to the database for a refreshed copy. |
@TimeOfDay(specified=false) |
optional |
|
alwaysRefresh |
Set to a boolean value of true to force all queries that go to the database to always refresh the cache. |
false |
optional |
|
refreshOnlyIfNewer |
Set to a boolean value of true to force all queries that go to the database to 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). Note: This option only applies if one of the other refreshing options, such as alwaysRefresh, is already enabled. Note: A version field is necessary to apply this feature. |
false |
optional |
|
disableHits |
Set to a boolean value of true to 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. |
false |
optional |
|
coordinationType |
Set this attribute to the cache coordination mode (org.eclipse.persistence.annotations.CacheCoordinationType enumerated type). |
CacheCoordinationType.SEND_OBJECT_CHANGES |
optional |
|
Example of @Cache Annotation
... @Entity @Cache( type=CacheType.SOFT, // Cache everything until the JVM decides memory is low. size=64000 // Use 64,000 as the initial cache size. expiry=36000000, // 10 minutes coordinationType=CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS // if cache coordination is used, only send invalidation messages. ) public class Employee { ... }