[Java programming language only]

Configuring the near cache to update the LAST_ACCESS_TIMEvalue for the TTL evictor in the data grid

[Version 8.6 and later]You can configure the near cache configured on the client to propagate time-to-live (TTL) read operations to the remote data grid. Configuring this propagation prevents cache entries from getting prematurely evicted from the remote data grid.

Before you begin

About this task

You can enable the near cache to update TTL metadata on the remote data grid by setting the nearCacheLastAccessTTLSyncEnabled property in the ObjectGrid descriptor XML file.

Procedure

  1. Set the nearCacheLastAccessTTLSyncEnabled attribute in the ObjectGrid descriptor XML file.
    Set this attribute on the same backingMap element on which you have the TTL evictor enabled. For more information, see ObjectGrid descriptor XML file.
    [Version 8.6 and later]nearCacheLastAccessTTLSyncEnabled
    [Version 8.6 and later]Set the value to true to enable time-to-live (TTL) information to be synchronized with the remote data grid. To enable a near cache for a dynamic cache instance, this value must be set to true. If you are not using a dynamic cache near cache, you must enable the LAST_ACCESS_TIME TTL evictor type when you enable this property.
    [Version 8.6.0.4 and later]Attention: Setting the value to true for a dynamic cache near cache is now optional.

    Default: false (Optional)

    In the following example, both maps in the Grid ObjectGrid element have a TTL evictor configured. The Map1 backingMap element also has synchronization with the remote data grid enabled.
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
     xmlns="http://ibm.com/ws/objectgrid/config">
        <objectGrids>
            <objectGrid name="Grid">         
                 <backingMap name="Map1" lockStrategy="OPTIMISTIC" nearCacheLastAccessTTLSyncEnabled="true"  
    							ttlEvictorType="LAST_ACCESS_TIME" timeToLive="60"  copyMode="COPY_TO_BYTES"/>
                 <backingMap name="Map2" lockStrategy="OPTIMISTIC" nearCacheLastAccessTTLSyncEnabled="false" 
    							ttlEvictorType="LAST_ACCESS_TIME" timeToLive="60" copyMode="COPY_TO_BYTES"/>
            </objectGrid>
        </objectGrids>
    ...
    ...
    </objectGridConfig>
  2. Restart the container servers and clients.

Results

When cache entries are added to the remote data grid, the same keys and values are inserted into the near cache on the client. When the client gets or fetches keys from the cache, the values are returned from the near cache. The TTL metadata is also sent to the remote data grid, so that the remote data grid has the most recent TTL information.