Jump to: navigation, search

Difference between revisions of "EclipseLink/FAQ/How to disable the shared cache?"

(New page: Category:EclipseLink/FAQ By default EclipseLink enables a shared object cache to cache objects read from the database to avoid repeated database access. If the database is changed di...)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:EclipseLink/FAQ]]
+
[[Category:EclipseLink FAQ|How to disable the shared cache]]
  
 
By default EclipseLink enables a shared object cache to cache objects read from the database to avoid repeated database access.  If the database is changed directly through JDBC, or by another application or server, the objects in the shared cache will be stale.
 
By default EclipseLink enables a shared object cache to cache objects read from the database to avoid repeated database access.  If the database is changed directly through JDBC, or by another application or server, the objects in the shared cache will be stale.
Line 9: Line 9:
 
* Cache coordination
 
* Cache coordination
  
The shared cache can also be disabled.  This can be done using the persistence unit property:
+
The shared cache can also be disabled.  This can be done using the EclipseLink persistence unit property:
 
<source lang="xml">
 
<source lang="xml">
 
<property name="eclipselink.cache.shared.default" value="false"/>
 
<property name="eclipselink.cache.shared.default" value="false"/>
 
</source>
 
</source>
  
Or can be selectively enabled/disabled using the <code>@Cache</code> annotation.
+
Or the JPA 2.0 persistence unit element:
 +
<source lang="xml">
 +
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
 +
</source>
 +
 
 +
 
 +
Or can be selectively enabled/disabled using the <code>@Cache</code> annotation:
  
 
<source lang="java">
 
<source lang="java">
 
@Entity
 
@Entity
@Cache(shared=false)
+
@Cache(isolation=ISOLATED)
 
public class Employee {
 
public class Employee {
 
   ...
 
   ...
Line 24: Line 30:
 
</source>
 
</source>
  
See, [[EclipseLink/Examples/JPA/Caching|Caching Example]] and [[Introduction_to_Cache_(ELUG)|Introduction to Cache]] for more information on caching.
+
Or the JPA 2.0 <code>@Cacheable</code> annotation:
 +
 
 +
<source lang="java">
 +
@Entity
 +
@Cacheable(false)
 +
public class Employee {
 +
  ...
 +
}
 +
</source>
 +
 
 +
Do not disable the cache by setting the <code>CacheType</code> to <code>None</code>, this can cause object identity issues.
 +
 
 +
See, [[EclipseLink/Examples/JPA/Caching|Caching Example]] and the [[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching|Caching]] section of the EclipseLink JPA User Guide for more information on caching.

Revision as of 08:32, 31 May 2012


By default EclipseLink enables a shared object cache to cache objects read from the database to avoid repeated database access. If the database is changed directly through JDBC, or by another application or server, the objects in the shared cache will be stale.

EclipseLink offers several mechanism to deal with stale data including:

  • Refreshing
  • Invalidation
  • Optimistic locking
  • Cache coordination

The shared cache can also be disabled. This can be done using the EclipseLink persistence unit property:

<property name="eclipselink.cache.shared.default" value="false"/>

Or the JPA 2.0 persistence unit element:

<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>


Or can be selectively enabled/disabled using the @Cache annotation:

@Entity
@Cache(isolation=ISOLATED)
public class Employee {
  ...
}

Or the JPA 2.0 @Cacheable annotation:

@Entity
@Cacheable(false)
public class Employee {
  ...
}

Do not disable the cache by setting the CacheType to None, this can cause object identity issues.

See, Caching Example and the Caching section of the EclipseLink JPA User Guide for more information on caching.