TopLink Essentials Caching

TopLink Essentials provides a shared object cache to all persistent objects by default.

If used in a cluster, or other programs access the database, there are several caching options in TopLink Essentials to handle stale data.
These can be accessed through persistence.xml properties or through the TopLink ClassDescriptor API through a DescriptorCustomizer.

Isolated cache (shared=false) : Allows the shared cache to be turned off for a class. ("toplink.cache.shared.<class>", ClassDesctiptor.setIsIsolated(boolean)).
Always refresh : Any query that accesses the database will refresh the cache objects. (ClassDescriptor.alwaysRefreshCache()). (this not NOT include queries that get a cache hit).
Only refresh if newer version : Makes use of the optimistic lock version field to avoid refreshing the cache if the version is the same. (ClassDescriptor.onlyRefreshIfNewerVersion) need to set this AND refresh).
Disable cache hits : Disables all cache hits (better to use an isolated cache instead). (ClassDescriptor.disableCacheHits()). (need to set this AND refresh).

You can also set the cache size and type. ("toplink.cache.type.<class>", "toplink.cache.size.<class>").

You can also access the TopLink cache through the EntityManager API and explicitly invalidate objects.

i.e.
((oracle.toplink.essentials.ejb.cmp3.EntityManager)entityManager.getDelegate()).getServerSession().getIdentityMapAccessor().invalidateClass(<class>);

In TopLink 11g (preview), and EclipseLink (incubation) there are also several other caching options, including cache invalidation, and cache coordination.

In terms of performance for bulk updates or deletes you can also consider using the JPA update-all, delete-all queries. These allow you to make large updates using JPQL and have optimal performance and ensure the cache is maintained.

See also, http://en.wikibooks.org/wiki/Java_Persistence/Caching, http://en.wikibooks.org/wiki/Java_Persistence/Locking