This project provides a module for Play Framework that enables the use of JCache compliant cache implementations as providers for the Play Cache API.
This module is intended as a full replacement for the default Play Cache implementation. It also requires a valid JCache implementation on the classpath.
It also requires a registered JCacheWrapper
extension to enable lifting limitations introduced by the JCache API compared to the Play Cache API.
For example, JCache does not allow per mapping expiry which is a feature of the Play Cache API.
By default Ehcache 3 is the provided JCache implementation and an Ehcache 3 based extension is registered for JCacheWrapper
.
It uses the same properties as the Play Cache module for defining caches.
The JCacheWrapper
provides two methods that are invoked in different contexts:
-
JCacheWrapper.enhanceConfiguration(String, javax.cache.configuration.Configuration)
is invoked when the JCache module needs to create aCache
because it does not exist yet in theCacheManager
. This enables JCache implementations to enhance cache configurations with provider specific features. The JCache module will invokejavax.cache.CacheManager.createCache(String, javax.cache.configuration.Configuration)
with the returned configuration. -
JCacheWrapper.valueWrapper(String)
is invoked when JCache module defines aCache
to be used in Play. This enables JCache implementations to wrap values if/when required, optionally linked with configuration enhancements. The returnedValueWrapper
simply has symmetric methods for wrapping and unwrapping values.
This sub module restores full functionality to the Play Cache API by enabling per mapping expiry.
This is limited to the following:
-
Caches must be created by the JCache module and not by initial configuration
-
Cache names will be matched with Ehcache cache templates to enable full Ehcache configuration scope
The implementation works by wrapping values to contain the desired expiration. If expiry is configured on the cache, it will be delegated to whenever the duration is not explicitly defined as a finite duration.
This module has been developped for Play 2.5.x
and requires at least Ehcache 3.1.3
to function properly.
play.modules.disabled += "play.api.cache.EhCacheModule"
See Play Cache documentation for more information
The module will register itself through its integrated reference.conf
.
This includes the registration of the Ehcache 3 based module providing the JCacheWrapper
implementation.