Monday, February 9, 2009

OpenJPA Caching

The JPA specification defines two levels of caching: one that is scoped to the Entity Manager and another that is scoped to the Persistent Unit. The Entity Manager level cache is associated with a current transaction unless you are using the Extended Context—in which you can scope the cache to the life cycle of a Stateful Session Bean. We discussed this life cycle earlier in the "Programming Model" section. The JPA Entity Manager has a flush method you can invoke to clear the cache and push changes to the database.

The Entity Manager cache is there is for keeping data around during a multi-request flow, often called a "conversation;" however, the persistence unit cache is meant to really be a performance booster for read-only or read-mostly data. OpenJPA provides a data-level cache at the persistence unit level. OpenJPA provides a Single JVM cache provider. This may be ideal for read-only data that is initialized during the startup of an application.

For Example:
<property name="openjpa.DataCache" value="true(CacheSize=5000, SoftReferenceSize=0)"/>
<property name="openjpa.QueryCache" value="CacheSize=1000, SoftReferenceSize=100"/>
<property name="openjpa.RemoteCommitProvider" value="sjvm"/>

"svjm" here means "single jvm". Is there any other option here? How to use caching in distributed environment?

No comments:

Post a Comment