Enabling object caching

The object cache is enabled implicitly if you configure an isolation level that requires the use of the cache—see “Configuring the logical isolation level”. To configure the cache settings explicitly, set the <persistentObject> attributes listed in Table 4-4.

Table 4-4: <persistentObject> attributes to configure object cache settings

Attribute

Description

cacheSize

The maximum number of database rows that will be held in cache. To avoid overflow, rows are removed from cache using a least-recently-used (LRU) discard strategy. If not set, the default is 1000.

cacheTimeout

The maximum number of seconds that a row stored in cache will be considered valid. This setting should not be used to attempt to control the cache size, because invalid rows are only discarded from cache when an attempt is made to access them. The default value of zero is interpreted as an infinite timeout.

cacheLock

When the name of the selected isolationLevel ends with “Cache,” this setting determines whether exclusive locks should be used to ensure that only one transaction at a time can access any cache entry. The purpose of this setting is to permit the use of caching with entities that have some level of update contention. This property should not be relied upon to ensure exclusive access to the underlying database table rows. It is best used in combination with optimistic concurrency control.

cacheLockTimeout

The number of seconds that a transaction will wait when trying to obtain a lock. If a lock is not acquired in this period, the transaction is rolled back.

cacheChildren

When query methods refer to this entity using the parentVersion attribute, the query methods must also be explicitly referenced by this entity using the cacheChildren attribute. Specify a comma-separated list of ChildEntity.QueryName entries such as:

Order.findByCustomer,Order.findByItem