Java Reference
In-Depth Information
database can be updated without using the persistence framework by either a
module written in JDBC or by a different application. In most applications you
need to arrange for the process-level cache to load the changed objects from the
database in order to prevent the application from working with old data.
There are three ways to do this:
Periodically invalidate cached objects —If the application can tolerate slightly
stale data, then you can configure the process-level cache to periodically
invalidate cached objects and force the latest copies to be loaded from the
database.
Broadcast change notifications —If the application is clustered, then you can
configure the persistence framework running in each application that
makes up the cluster to broadcast change notifications so that other cluster
members know to invalidate cached copies of the changed objects.
Programmatically invalidate cached objects —If the application has bypassed the
persistence framework and updated the database using some other mecha-
nism such as JDBC , you can programmatically invalidate cached objects and
force them to be reloaded. This approach can only be used by applications
that are aware of the process-level cache.
Cached objects that are updateable should typically use optimistic locking (see
chapter 12) because that will prevent the application from blindly overwriting
changes in the database. If a transaction updates a cached object that had already
been changed in the database, the optimistic locking failure will cause the trans-
action to be rolled back. The persistence framework will remove the stale data
from the cache, and the application can retry transaction with the latest version
of the data.
Despite the complication of handling updated objects, a process-level cache is
an extremely useful way to improve the performance of an application that uses a
persistence framework.
Query caching
Hibernate and some JDO implementations also provide a query cache, which
stores the primary keys of the objects found by a query. When it executes a query,
the ORM framework looks in the query cache for the result before accessing the
database. If the query cache contains the results of the query, the framework then
looks up the objects in the process-level cache. A query cache can sometimes
improve performance but is only useful for read-only data because the ORM
framework flushes all cached queries that involve a modified table.
 
 
Search WWH ::




Custom Search