Refresh Ahead Caching
As of version 2.7, Ehcache provides a Refresh Ahead cache decorator that can improve cache performance by asynchronously refreshing cache entries. The refresh ahead cache is configured with a time-to-refresh (TTR) value, in addition to time-to-live (TTL) and (optional) time-to-idle (TTI) values. A refresh is triggered when a non-expired cache entry is accessed if more than TTR seconds have elapsed since creating of the cache. For example, suppose we set TTR=30s, TTL=60s, and no TTI. Then, any cache entry that is accessed between 30s and 60s after creation will trigger the asynchronous refresh.
Refresh ahead caching is configured in the plugin’s properties file using the following options:
• <plugin name>.cache.<cache name>.decorators: CSV list of decorators to apply to the cache. Currently, the only supported option is refreshAhead.
• <plugin name>.cache.<cache name>.refreshAhead.
timeToRefreshSeconds: The number of seconds an entry can exist in the cache before it is refreshed on access. Expired items that have yet to be evicted cannot be refreshed. (REQUIRED.)
• <plugin name>.cache.<cache name>.refreshAhead.
maximumBacklogItems: The maximum number of refresh requests allowed in the refresh work queue. Once this limit is exceeded, items are dropped from the queue to prevent potentially overtaxing resources. (REQUIRED.)
• <plugin name>.cache.<cache name>.refreshAhead.batchSize: The maximum number of refresh requests that can be batched for processing by a thread. For more frequent processing of requests—at a cost to performance—lower the value. Defaults value is 100.
• <plugin name>.cache.<cache name>.refreshAhead.numberOfThreads: The number of threads to use for background refresh operations on the decorator. Defaults value is 1.
• <plugin name>.cache.<cache name>.refreshAhead.evictOnLoadMiss: Force an immediate eviction on a reload miss (true) or to not evict before normal eviction takes effect (false). Default value is false.