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/Basic JPA Development/Caching"

m
Line 4: Line 4:
 
*[[EclipseLink/Examples/JPA/Caching|Caching]]
 
*[[EclipseLink/Examples/JPA/Caching|Caching]]
 
}}
 
}}
=Caching Overview=
+
=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:
+
The EclipseLink cache is an in-memory repository that stores recently read or written objects based on class and primary key values.  
 +
Caching is discussed in the following topics:
  
* Improve performance by holding recently read or written objects and accessing them in-memory to minimize database access.
+
*[[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Caching Overview|Caching Overview]]  
* Manage locking and isolation level.
+
*[[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Shared and Isolated|Shared and Isolated]]  
* Manage object identity.
+
*[[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Type and Size|Type and Size]]  
 
+
*[[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Expiration|Expiration]]
For more information about the EclipseLink cache and its default behavior, see [[Introduction%20to%20Cache%20(ELUG)|Introduction to Cache]].
+
*[[EclipseLink/UserGuide/JPA/Basic JPA Development/Caching/Coordination|Coordination]]
 
+
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]]
+
 
+
==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>
+
 
+
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.
+
 
+
'''''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>
+
  
  
 
{{EclipseLink_JPA
 
{{EclipseLink_JPA
 
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Locking/Optimistic Locking|Optimistic Locking]]
 
|previous= [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Locking/Optimistic Locking|Optimistic Locking]]
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Shared and Isolated|Shared and Isolated]]
 
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development|Basic JPA Development]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development|Basic JPA Development]]
 +
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Caching Overview|Caching Overview]]
 
|version=2.2.0 DRAFT}}
 
|version=2.2.0 DRAFT}}

Revision as of 11:37, 18 February 2011


Eclipselink-logo.gif
EclipseLink
Website
Download
Community
Mailing ListForumsIRCmattermost
Issues
OpenHelp WantedBug 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. Caching is discussed in the following topics:


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

Copyright © Eclipse Foundation, Inc. All Rights Reserved.