Hitachi

uCosminexus Application Server Compatibility Guide


9.7.1 Processing of the cache functionality

If you use the cache functionality, when the same entity is read, the data is obtained from the cache instead of the database. This section describes the procedure for processing the cache functionality, the cache registration and update timing, and the procedure for updating the cache.

Organization of this subsection

(1) Procedure for processing the cache functionality

The following figure shows the flow of processing of the cache functionality.

Figure 9‒13: Flow of processing of the cache functionality

[Figure]

A description of the above figure is as follows:

When the entity has a relationship and when you obtain the relationship destination entity, if the target entity exists in the cache, the entity in the cache is referenced without accessing the database.

A cache exists for each persistence context.

(2) Cache registration and update timing

Registration and update in a cache is implemented at the following times:

(3) Procedure for updating the cache

The following figure shows the flow of updating the cache.

Figure 9‒14: Updating the cache

[Figure]

A description of the figure is as follows:

  1. The following operations are implemented for the entity object:

    • refresh operation

    • Transaction commit

  2. During the refresh operation, the database is accessed.

  3. The data existing in the persistence context is registered in the cache and the cache data is updated.

Note that the cache is registered even when JPQL is executed. The cache is registered if JPQL is executed when the target cache does not exist. The cache data is used in JPQL as well, but the database is accessed irrespective of the presence or absence of the cache data. Therefore, the cache-based processing performance cannot be expected to improve. For details, see point (4).

The cache stores information for the entity objects; therefore, if the object returned during the execution of the query is the entity itself, the cache is updated. The cache is not updated when other fields are specified. The JPQL examples when the cache update is valid and when the update is invalid are as follows:

(4) Relation between JPQL and cache

When all the entity objects are obtained with JPQL, if there is information registered in the cache, the cache information is obtained. The cache functionality of Cosminexus JPA Provider requires a primary key that is the ID for identifying the target entity. To obtain the primary key, the JPQL result must be obtained and at this time, the database is accessed. The primary key is extracted from the database access results and the entity object is obtained from the cache. Also, if the target data does not exist in the cache, the entity is created from the database information.

With JPQL, the database is accessed regardless of the presence or absence of the cache data. Therefore, for JPQL, cache-based performance improvement cannot be expected.