Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Caching"

From Eclipsepedia

Jump to: navigation, search
m
m (EclipseLink JPA Extensions for Entity Caching)
Line 26: Line 26:
  
 
==EclipseLink JPA Extensions for Entity Caching==
 
==EclipseLink JPA Extensions for Entity Caching==
 +
You may define the <tt>@Cache</tt> annotation on the following:
 +
* <tt>@Entity</tt>
 +
* <tt>@MappedSuperclass</tt>;
 +
* the root of the inheritance hierarchy (if applicable).<br>
  
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:
+
If you define the <tt>@Cache</tt> annotation on an inheritance subclass, the annotation will be ignored. If you define the <tt>@Cache</tt> annotation on <tt>@Embeddable</tt> EclipseLink will throw an exception.
 
+
* 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 [[Introduction%20to%20Cache%20(ELUG)|Introduction to Cache]].
+
 
+
EclipseLink defines the following entity caching annotations:
+
 
+
* <tt>[[#How to Use the @Cache Annotation|@Cache]]</tt>
+
* <tt>[[#How to Use the @TimeOfDay Annotation|@TimeOfDay]]</tt>
+
* <tt>[[#How to Use the @ExistenceChecking Annotation|@ExistenceChecking]]</tt>
+
 
+
EclipseLink also provides a number of persistence unit properties that you can specify to configure the EclipseLink cache (see [[#How to Use the Persistence Unit Properties for Caching|How to Use the Persistence Unit Properties for Caching]]). These properties may compliment or provide an alternative to the usage of annotations.  
+
 
+
For more information, see the following:
+
* [[#What You May Need to Know About Overriding Annotations in JPA|What You May Need to Know About Overriding Annotations in JPA]]
+
* [[#What You May Need to Know About Using EclipseLink JPA Persistence Unit Properties|What You May Need to Know About Using EclipseLink JPA Persistence Unit Properties]]
+
  
 +
'''''Example of @Cache Annotation '''''
 +
<source lang="java">
 +
...
 +
@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 {
 +
  ...
 +
}
 +
</source>
  
  

Revision as of 07:34, 25 June 2010


link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

Elug example icon.png Examples

Caching

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 Introduction to Cache.

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 (see How to Use the Persistence Unit Properties for Caching). These properties may compliment or provide an alternative to the usage of annotations.

For more information, see the following:

EclipseLink JPA Extensions for Entity Caching

You may 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.

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 {
  ...
}


Eclipselink-logo.gif
Version: DRAFT
Other versions...