Title: Object Caching
Cayenne implements an advanced caching mechanism that has a goal of improving application performance and ensuring data consistency both across Java applications and sessions within the same application. The following classes participate in the caching mechanism:
Cayenne implements the following levels of caching:
Caching properties are configured using CayenneModeler for each application DataDomain. Application code is normally independent from a chosen level, i.e., it does not have to be changed when caching is reconfigured. Details on caching configuration are provided in the Modeler Guide.
DataRowStore posts SnapshotEvents for any changes made to the cache. ObjectStore(s) using a given DataRowStore are automatically registered as listeners for SnapshotEvents and update their state accordingly. Application objects can also take advantage of the events by implementing SnapshotEventListener interface and registering with EventManager
SnapshotEventListener customListener = ...
DataDomain domain = Configuration.getSharedConfiguration().getDomain();
DataRowStore cache = domain.getSharedSnapshotCache();
domain.getEventManager().addListener(
customListener,
"snapshotsChanged",
SnapshotEvent.class,
cache.getSnapshotEventSubject());
Upgrading to Cayenne 1.2 and Newer Cayenne 1.1 used a singleton EventManager accessible via EventManager.getDefaultManager(). Note that now EventManager is obtained from DataDomain or DataContext. Make sure that you register your listeners with an appropriate EventManager. |
If two or more users update their local copies of the same object, Cayenne implements the following behavior: