Built over the Jedis connector and Akka serialization for maximum flexibility. One of the main goal is to provide a consistent implementation over multiple Play framework versions to allow interoperability.
- Akka serialization for pluggable serialization protocols.
- Compression of larger values to reduce latency.
- 2-tier cache system, recent keys are kept in a local cache.
Add this GitHub maven package repository to your build: willtrnr/maven-repo
Then add the dependency with the correct Play major and minor suffix:
libraryDependencies += "net.archwill.play" %% "play-redis" % "1.0.5.play26"
Check for the latest version in the download badge above, also use the version suffix matching your Play's major and minor release. Play version 2.4.x to 2.7.x are fully supported.
Then enable the module in your configuration, while disabling Ehcache:
play.modules.disabled += "play.api.cache.EhCacheModule"
play.modules.enabled += "net.archwill.play.redis.RedisModule"
Add the proper configuration to connect to your Redis server, minimally this should include the host and port to use:
redis {
host = "localhost"
port = 6379
}
Check out the other possible knobs and defaults in reference.conf.
Objects will be serialized using Akka Serialization making it possible to use Kryo or any other saner alternative than Java serialization. Read the Akka documentation for how to set this up.
This plugin also makes use of a local cache to speed up lookups for recent keys. When retrofitting caching in a legacy system making inneficient use of database requests with duplicated queries this can greatly help the response time.
A Redis Pub-Sub channel is used to communicate the invalidations, which may introduce a slight delay between when a key is changed and when every application instance is aware of it. Depending on how your application makes use of the cache this may be a source of issues.
If needed, disabled it by setting the redis.local-cache.max-size
configuration
key to 0. You may also want to tweak that value depending on the number of
unique keys used and the heap memory available.
Some scenarios where it could be desirable to disable the local cache include:
- The keys used are vastly different with each request
- Your application is sensitive to data freshness
- Keys are not requested more than once per request
- Cache keys are changing extremely often