Enabling query caching

Query caching allows EAServer to cache the values returned by finder and ejbSelect method queries. When caching is enabled for a query, the key values returned by each invocation are cached in memory, with the method input parameter values serving as the cache key. Together with entity object caching, query caching can reduce the number of unnecessary database reads.

To enable caching for a finder or ejbSelect query, append [cache] to the end of the Query Mapping property value that corresponds to the method. For example:

[default][cache]

Or, for a query mapped to an EJB-QL query:

ejbQuery:[cache]

You can specify optional parameters with this syntax:

[cache cache-params]

Where cache-params is a list of parameters listed in Table 4-5, with each parameter separated from the next by white space, for example:

[default][cache size=1M timeout=10]
Table 4-5: Query cache configuration parameters

Parameter

To indicate

name=name

The cache name. Specifying a named cache allows multiple queries to use one cache. The named cache must be created and configured as described for named object caches in “Configuring object caching”.

Only one of name or size may be specified.

size=size

The cache size. Only one of name or size may be specified. The value syntax is:

  • nM or nm to specify a size in Megabytes, for example: 1M

  • nK or nk to specify a size in kilobytes, for example: 512k

  • n to specify a size in bytes, for example: 1048576

timeout=seconds

The cache timeout in seconds. A value of 0 indicates infinity.

verify

Specifies that finder results must be verified at the end of the transaction. Restrictions apply—see “Verifying cached finder method results” for more information.

ignore insert

If database change notification is enabled, inserts do not invalidate the cache.

ignore delete

If database change notification is enabled, deletes do not invalidate the cache.

ignore update

If database change notification is enabled, updates do not invalidate the cache.

Verifying cached finder method results To obtain verified finder method semantics, include the keyword verify in the cache settings for the finder query. For example, use [cache verify] in place of [cache]. For components using object caching, this setting specifies that any finder method data used from cache should be verified at commit time with an appropriate database query. The verification query runs with an isolation level that is equivalent to higher than the component isolation level. Query cache verification requires the use of a table-level timestamp, and all tables referenced in the SQL query must use the same table timestamp as the entity bean for which the finder method is defined.