Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/2.4/a cache"

m
Line 4: Line 4:
 
|category=JPA
 
|category=JPA
 
|release=2.4.x
 
|release=2.4.x
|title=}}
+
|title=TLJPA}}
 
<span class="metaname">    </span>
 
<span class="metaname">    </span>
  
 
{| class="simple oac_no_warn" width="100%"
 
{| class="simple oac_no_warn" width="100%"
 
| align="left" valign="top" |   
 
| align="left" valign="top" |   
| width="144" align="right" valign="bottom" |
+
| width="185" align="right" valign="bottom" |
 
{| class="simple oac_no_warn" width="100%"
 
{| class="simple oac_no_warn" width="100%"
 
|
 
|
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[[EclipseLink/UserGuide/JPA/toc| Contents]]
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
 
|}
 
|}
 
|}
 
|}
Line 21: Line 21:
 
----
 
----
  
{| width="150"
+
{| width="165"
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_batchfetch|&lt;- Previous]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_batchfetch| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cacheindex|Next -&gt;]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_cacheindex| Next ]][[Image:Elug_next_icon.png|Next]]
 
|
 
|
 
|}
 
|}
 +
 +
[[Image:Elug_draft_icon.png|Warning]]Beta Draft: 2012-06-18
  
 
<span id="CHDBBIHE"></span>
 
<span id="CHDBBIHE"></span>
Line 37: Line 39:
 
Use <code>@Cache</code>) to configure the EclipseLink object cache. By default, EclipseLink uses a shared object cache to cache all objects. You can configure the caching type and options on a per class basis to allow optimal caching.
 
Use <code>@Cache</code>) to configure the EclipseLink object cache. By default, EclipseLink uses a shared object cache to cache all objects. You can configure the caching type and options on a per class basis to allow optimal caching.
  
<span id="sthref35"></span>
+
<span id="sthref33"></span>
  
 
''' '''
 
''' '''
Line 43: Line 45:
 
===Annotation Elements===
 
===Annotation Elements===
  
[[#CDEJJHDG|Table 2-1]] describes this annotation's elements.
+
[[#CDEJJHDG|Table 2-4]] describes this annotation's elements.
  
<span id="sthref36"></span><span id="CDEJJHDG"></span>
+
<span id="sthref34"></span><span id="CDEJJHDG"></span>
  
'''''Table 2-1 @Cache Annotation Elements'''''
+
'''''Table 2-4 @Cache Annotation Elements'''''
  
 
{| class="HRuleFormalWide" dir="ltr" title="@Cache Annotation Elements" summary="This table describes the list of attributes for this annotation." width="100%" border="1" frame="hsides" rules="rows" cellpadding="3" frame="hsides" rules="rows"
 
{| class="HRuleFormalWide" dir="ltr" title="@Cache Annotation Elements" summary="This table describes the list of attributes for this annotation." width="100%" border="1" frame="hsides" rules="rows" cellpadding="3" frame="hsides" rules="rows"
 
|- align="left" valign="top"
 
|- align="left" valign="top"
! id="r1c1-t2" align="left" valign="bottom" | '''Annotation Element'''
+
! id="r1c1-t7" align="left" valign="bottom" | '''Annotation Element'''
! id="r1c2-t2" align="left" valign="bottom" | '''Description'''
+
! id="r1c2-t7" align="left" valign="bottom" | '''Description'''
! id="r1c3-t2" align="left" valign="bottom" | '''Default'''
+
! id="r1c3-t7" align="left" valign="bottom" | '''Default'''
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r2c1-t2" headers="r1c1-t2" align="left" |
+
| id="r2c1-t7" headers="r1c1-t7" align="left" |
 
<code>type</code>
 
<code>type</code>
| headers="r2c1-t2 r1c2-t2" align="left" |
+
| headers="r2c1-t7 r1c2-t7" align="left" |
 
(Optional) Set this attribute to the type (org.eclipse.persistence.annotations.CacheType enumerated type) of the cache that you will be using:
 
(Optional) Set this attribute to the type (org.eclipse.persistence.annotations.CacheType enumerated type) of the cache that you will be using:
  
Line 72: Line 74:
 
* <code>eclipselink.cache.type.&lt;</code>''<code>ENTITY</code>''<code>&gt;</code>
 
* <code>eclipselink.cache.type.&lt;</code>''<code>ENTITY</code>''<code>&gt;</code>
 
* <code>eclipselink.cache.type.default</code>
 
* <code>eclipselink.cache.type.default</code>
| headers="r2c1-t2 r1c3-t2" align="left" |
+
| headers="r2c1-t7 r1c3-t7" align="left" |
 
<code>CacheType.SOFT_WEAK</code>
 
<code>CacheType.SOFT_WEAK</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r3c1-t2" headers="r1c1-t2" align="left" |
+
| id="r3c1-t7" headers="r1c1-t7" align="left" |
 
<code>size</code>
 
<code>size</code>
| headers="r3c1-t2 r1c2-t2" align="left" |
+
| headers="r3c1-t7 r1c2-t7" align="left" |
 
(Optional) Set this attribute to an int value to define the size of cache to use (number of objects).
 
(Optional) Set this attribute to an int value to define the size of cache to use (number of objects).
| headers="r3c1-t2 r1c3-t2" align="left" |
+
| headers="r3c1-t7 r1c3-t7" align="left" |
 
<code>100</code>
 
<code>100</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r4c1-t2" headers="r1c1-t2" align="left" |
+
| id="r4c1-t7" headers="r1c1-t7" align="left" |
 
<code>shared</code>
 
<code>shared</code>
| headers="r4c1-t2 r1c2-t2" align="left" |
+
| headers="r4c1-t7 r1c2-t7" align="left" |
 
(Optional) 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.
 
(Optional) 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.
  
 
* <code>true</code> —use shared cache for cached instances.
 
* <code>true</code> —use shared cache for cached instances.
 
* <code>false</code>—use client isolated cache for cached instances (no L2 cache).
 
* <code>false</code>—use client isolated cache for cached instances (no L2 cache).
| headers="r4c1-t2 r1c3-t2" align="left" |
+
| headers="r4c1-t7 r1c3-t7" align="left" |
 
<code>true</code>
 
<code>true</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r5c1-t2" headers="r1c1-t2" align="left" |
+
| id="r5c1-t7" headers="r1c1-t7" align="left" |
 
<code>expiry</code>
 
<code>expiry</code>
| headers="r5c1-t2 r1c2-t2" align="left" |
+
| headers="r5c1-t7 r1c2-t7" align="left" |
 
(Optional) 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.
 
(Optional) 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.
| headers="r5c1-t2 r1c3-t2" align="left" |
+
| headers="r5c1-t7 r1c3-t7" align="left" |
 
.<code>-1</code> (no expiry)
 
.<code>-1</code> (no expiry)
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r6c1-t2" headers="r1c1-t2" align="left" |
+
| id="r6c1-t7" headers="r1c1-t7" align="left" |
 
<code>expiryTimeOfDay</code>
 
<code>expiryTimeOfDay</code>
| headers="r6c1-t2 r1c2-t2" align="left" |
+
| headers="r6c1-t7 r1c2-t7" align="left" |
 
(Optional) 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.
 
(Optional) 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.
| headers="r6c1-t2 r1c3-t2" align="left" |
+
| headers="r6c1-t7 r1c3-t7" align="left" |
 
<code>@TimeOfDay(specified=false)</code>
 
<code>@TimeOfDay(specified=false)</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r7c1-t2" headers="r1c1-t2" align="left" |
+
| id="r7c1-t7" headers="r1c1-t7" align="left" |
 
<code>alwaysRefresh</code>
 
<code>alwaysRefresh</code>
| headers="r7c1-t2 r1c2-t2" align="left" |
+
| headers="r7c1-t7 r1c2-t7" align="left" |
 
(Optional) Set to a boolean value of true to force all queries that go to the database to always refresh the cache
 
(Optional) Set to a boolean value of true to force all queries that go to the database to always refresh the cache
| headers="r7c1-t2 r1c3-t2" align="left" |
+
| headers="r7c1-t7 r1c3-t7" align="left" |
 
<code>false</code>
 
<code>false</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r8c1-t2" headers="r1c1-t2" align="left" |
+
| id="r8c1-t7" headers="r1c1-t7" align="left" |
 
<code>refreshOnlyIfNewer</code>
 
<code>refreshOnlyIfNewer</code>
| headers="r8c1-t2 r1c2-t2" align="left" |
+
| headers="r8c1-t7 r1c2-t7" align="left" |
 
(Optional) 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).
 
(Optional) 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).
  
Line 122: Line 124:
 
* This option only applies if one of the other refreshing options, such as alwaysRefresh, is already enabled.
 
* This option only applies if one of the other refreshing options, such as alwaysRefresh, is already enabled.
 
* A version field is necessary to apply this feature.
 
* A version field is necessary to apply this feature.
| headers="r8c1-t2 r1c3-t2" align="left" |
+
| headers="r8c1-t7 r1c3-t7" align="left" |
 
<code>false</code>
 
<code>false</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r9c1-t2" headers="r1c1-t2" align="left" |
+
| id="r9c1-t7" headers="r1c1-t7" align="left" |
 
<code>disableHits</code>
 
<code>disableHits</code>
| headers="r9c1-t2 r1c2-t2" align="left" |
+
| headers="r9c1-t7 r1c2-t7" align="left" |
 
(Optional) 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.
 
(Optional) 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.
| headers="r9c1-t2 r1c3-t2" align="left" |
+
| headers="r9c1-t7 r1c3-t7" align="left" |
 
<code>false</code>
 
<code>false</code>
 
|- align="left" valign="top"
 
|- align="left" valign="top"
| id="r10c1-t2" headers="r1c1-t2" align="left" |
+
| id="r10c1-t7" headers="r1c1-t7" align="left" |
 
<code>coordinationType</code>
 
<code>coordinationType</code>
| headers="r10c1-t2 r1c2-t2" align="left" |
+
| headers="r10c1-t7 r1c2-t7" align="left" |
 
(Optional) Set this attribute to the cache coordination mode (<code>org.eclipse.persistence.annotations.CacheCoordinationType</code> enumerated type).
 
(Optional) Set this attribute to the cache coordination mode (<code>org.eclipse.persistence.annotations.CacheCoordinationType</code> enumerated type).
| headers="r10c1-t2 r1c3-t2" align="left" |
+
| headers="r10c1-t7 r1c3-t7" align="left" |
 
<code>CacheCoordinationType.SEND_OBJECT_CHANGES</code>
 
<code>CacheCoordinationType.SEND_OBJECT_CHANGES</code>
 
|}
 
|}
Line 142: Line 144:
 
<br />
 
<br />
  
<span id="sthref37"></span>
+
<span id="sthref35"></span>
  
 
''' '''
 
''' '''
Line 156: Line 158:
 
If you define the <code>@Cache</code> annotation on an inheritance subclass, the annotation will be ignored. If you define the <code>@Cache</code> annotation on <code>@Embeddable</code> EclipseLink will throw an exception.
 
If you define the <code>@Cache</code> annotation on an inheritance subclass, the annotation will be ignored. If you define the <code>@Cache</code> annotation on <code>@Embeddable</code> EclipseLink will throw an exception.
  
<span id="sthref38"></span>
+
<span id="sthref36"></span>
  
 
'''Caching in EclipseLink'''
 
'''Caching in EclipseLink'''
Line 174: Line 176:
  
 
* <code>@Cache</code>
 
* <code>@Cache</code>
* <code>[[EclipseLink/UserGuide/JPA/a_timeofday|@TimeOfDay]]</code>
+
* <code>[[EclipseLink/UserGuide/JPA/2.4/a_timeofday|@TimeOfDay]]</code>
* <code>[[EclipseLink/UserGuide/JPA/a_existencechecking|@ExistenceChecking]]</code>
+
* <code>[[EclipseLink/UserGuide/JPA/2.4/a_existencechecking|@ExistenceChecking]]</code>
  
 
EclipseLink also provides a number of persistence unit properties that you can specify to configure the EclipseLink cache. These properties may compliment or provide an alternative to the usage of annotations.
 
EclipseLink also provides a number of persistence unit properties that you can specify to configure the EclipseLink cache. These properties may compliment or provide an alternative to the usage of annotations.
Line 185: Line 187:
 
* What You May Need to Know About Using EclipseLink JPA Persistence Unit Properties <code>http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#What_You_May_Need_to_Know_About_Using_EclipseLink_JPA_Persistence_Unit_Properties</code>
 
* What You May Need to Know About Using EclipseLink JPA Persistence Unit Properties <code>http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#What_You_May_Need_to_Know_About_Using_EclipseLink_JPA_Persistence_Unit_Properties</code>
  
<span id="sthref39"></span>
+
<span id="sthref37"></span>
  
 
''' '''
 
''' '''
Line 191: Line 193:
 
===Examples===
 
===Examples===
  
[[#CHDEEGCI|Example 2-1]] illustrates an <code>@Cache</code> annotation.
+
[[#CHDEEGCI|Example 2-10]] illustrates an <code>@Cache</code> annotation.
  
 
<span id="CHDEEGCI"></span>
 
<span id="CHDEEGCI"></span>
  
'''''Example 2-1 Using @Cache Annotation'''''
+
'''''Example 2-10 Using @Cache Annotation'''''
  
 
   
 
   
Line 210: Line 212:
 
  }
 
  }
  
<span id="sthref40"></span>
+
[[#CDEJDBFJ|Example 2-11]] shows how to use this annotation in the <code>eclipselink-orm.xml</code> file.
  
'''''Example 2-2 Using &lt;cache&gt; Element'''''
+
<span id="CDEJDBFJ"></span>
 +
 
 +
'''''Example 2-11 Using &lt;cache&gt; Element'''''
  
 
   
 
   
Line 229: Line 233:
 
You can also specify caching properties at the persistence unit level (in the <code>persistence.xml</code> file) as shown here:
 
You can also specify caching properties at the persistence unit level (in the <code>persistence.xml</code> file) as shown here:
  
<span id="sthref41"></span>
+
<span id="sthref38"></span>
  
'''''Example 2-3 Using persistence.xml'''''
+
'''''Example 2-12 Specifying Caching in persistence.xml'''''
  
 
   
 
   
Line 251: Line 255:
 
  &lt;/persistence&gt;
 
  &lt;/persistence&gt;
  
<span id="sthref42"></span>
+
<span id="sthref39"></span>
  
 
''' '''
 
''' '''
Line 259: Line 263:
 
For more information, see:
 
For more information, see:
  
* [[EclipseLink/UserGuide/JPA/a_existencechecking|"@ExistenceChecking"]]
+
* [[EclipseLink/UserGuide/JPA/2.4/a_existencechecking|"@ExistenceChecking"]]
* [[EclipseLink/UserGuide/JPA/a_timeofday|"@TimeOfDay"]]
+
* [[EclipseLink/UserGuide/JPA/2.4/a_timeofday|"@TimeOfDay"]]
 +
* [[EclipseLink/UserGuide/JPA/2.4/a_cacheinterceptor|"@CacheInterceptor"]]
 
* "Configuring Caching" <code></code>
 
* "Configuring Caching" <code></code>
* [[EclipseLink/UserGuide/JPA/a_cacheinterceptor|"@CacheInterceptor"]]
+
 
 +
<span id="footerspace"> </span>
  
 
----
 
----
Line 269: Line 275:
 
|-
 
|-
 
| valign="bottom" |
 
| valign="bottom" |
{| width="150"
+
{| width="165"
 
|-
 
|-
 
|
 
|
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_batchfetch|&lt;- Previous]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_batchfetch| Previous ]]<span class="previouslink">[[Image:Elug_previous_icon.png|Previous]]</span>
 
| align="center" |
 
| align="center" |
[[EclipseLink/UserGuide/JPA/a_cacheindex|Next -&gt;]]
+
[[EclipseLink/UserGuide/JPA/2.4/a_cacheindex| Next ]][[Image:Elug_next_icon.png|Next]]
 
|}
 
|}
 
| width="34%" align="center" |
 
| width="34%" align="center" |
[[Image:Eclipselink-logo.gif|150px|EclispeLink]]<br />[http://wiki.eclipse.org/EclipseLink EclipseLink Home]<br />
+
[[Image:Eclipselink-logo.gif|150px|EclispeLink]]<br />[[Image:Elug_home_icon.png|EclipseLink logo]] [http://www.eclipse.org/eclipselink/ EclipseLink Home] • [[Image:Elug_pdf.png|PDF]] PDF (coming soon)<br />
 
| align="right" valign="bottom" |
 
| align="right" valign="bottom" |
 
{| class="simple oac_no_warn" width="225"
 
{| class="simple oac_no_warn" width="225"
 
|
 
|
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
+
[[Image:Elug_Magnifier.png|Search]][http://www.google.com/cse/home?cx=016171230611334810008:y5kxq4rqd8s&hl=en Search]
 
| align="center" valign="top" |
 
| align="center" valign="top" |
[[EclipseLink/UserGuide/JPA/toc| Contents]]
+
&nbsp;&nbsp;&nbsp;[[Image:Elug_guide_icon.png|Contents]][[EclipseLink/UserGuide/JPA/2.4/toc| Contents]]
 
|}
 
|}
 
|}
 
|}

Revision as of 14:17, 19 June 2012


Java Persistence API (JPA) Extensions Reference for EclipseLink, 2.4.x

SearchSearch

   Contents Contents


Previous Previous

Next Next

WarningBeta Draft: 2012-06-18


@Cache

Use @Cache) to configure the EclipseLink object cache. By default, EclipseLink uses a shared object cache to cache all objects. You can configure the caching type and options on a per class basis to allow optimal caching.

Annotation Elements

Table 2-4 describes this annotation's elements.

Table 2-4 @Cache Annotation Elements

Annotation Element Description Default

type

(Optional) Set this attribute to the type (org.eclipse.persistence.annotations.CacheType enumerated type) of the cache that you will be using:

  • FULL
  • WEAK
  • SOFT
  • SOFT_WEAK
  • HARD_WEAK
  • CACHE (not recommended)
  • NONE (not recommended, use shared=false instead)

You can override this attribute with these persistence unit properties:

  • eclipselink.cache.type.<ENTITY>
  • eclipselink.cache.type.default

CacheType.SOFT_WEAK

size

(Optional) Set this attribute to an int value to define the size of cache to use (number of objects).

100

shared

(Optional) 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 —use shared cache for cached instances.
  • false—use client isolated cache for cached instances (no L2 cache).

true

expiry

(Optional) 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)

expiryTimeOfDay

(Optional) 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)

alwaysRefresh

(Optional) Set to a boolean value of true to force all queries that go to the database to always refresh the cache

false

refreshOnlyIfNewer

(Optional) 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 Note:

  • This option only applies if one of the other refreshing options, such as alwaysRefresh, is already enabled.
  • A version field is necessary to apply this feature.

false

disableHits

(Optional) 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

coordinationType

(Optional) Set this attribute to the cache coordination mode (org.eclipse.persistence.annotations.CacheCoordinationType enumerated type).

CacheCoordinationType.SEND_OBJECT_CHANGES


Usage

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.

Caching in EclipseLink

The EclipseLink cache is an in-memory repository that stores recently read or written objects based on class and primary key values. EclipseLink uses the cache to do the following:

  • Improve performance by holding recently read or written objects and accessing them in-memory to minimize database access.
  • Manage locking and isolation level.
  • Manage object identity.

For more information about the EclipseLink cache and its default behavior, see:

EclipseLink defines the following entity caching annotations:

EclipseLink also provides a number of persistence unit properties that you can specify to configure the EclipseLink cache. These properties may compliment or provide an alternative to the usage of annotations.

For more information, see the following:

Examples

Example 2-10 illustrates an @Cache annotation.

Example 2-10 Using @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 {
  ...
}

Example 2-11 shows how to use this annotation in the eclipselink-orm.xml file.

Example 2-11 Using <cache> Element


<?xml version="1.0"?>
<entity-mappings
  xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm
  http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_4.xsd"
  version="2.4">
    <entity name="Employee" class="org.acme.Employee" access="FIELD">
      <cache type="SOFT" size="64000" expiry="36000000" coordination-type="INVALIDATE_CHANGED_OBJECTS"/>
    </entity>
</entity-mappings>

You can also specify caching properties at the persistence unit level (in the persistence.xml file) as shown here:

Example 2-12 Specifying Caching in persistence.xml


<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_2_0.xsd"
  version="2.0">
    <persistence-unit name="acme" transaction-type="RESOURCE_LOCAL">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
          <property name="eclipselink.cache.shared.default" value="false"/>
          <property name="eclipselink.cache.shared.Employee" value="true"/>
          <property name="eclipselink.cache.type.Employee" value="SOFT"/>
          <property name="eclipselink.cache.size.Employee" value="64000"/>
        </properties>
    </persistence-unit>
</persistence>

See Also

For more information, see:

 


Previous Previous

Next Next

EclispeLink
EclipseLink logo EclipseLink Home • PDF PDF (coming soon)

SearchSearch

   Contents Contents

Back to the top