An Ebean L2 cache implementation using Redis via the Lettuce client.
This library provides a Redis-based L2 cache implementation for the Ebean ORM using the high-performance Lettuce Redis client. It supports distributed caching in clustered environments with features like:
- Near cache implementation for improved read performance
- L2 cache invalidation through Redis pub/sub
- Query cache invalidation
- Table modification notifications
- Java 21 or higher
- Ebean 15.11.0 or higher
- Redis server
Add the dependency to your Maven project:
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>ebean-lettuce</artifactId>
<version>1.0.0</version>
</dependency>Add Redis configuration to your application.yaml or application.properties:
ebean:
lettuce:
server: localhost
port: 6379
# Optional settings
# password: yourpassword
# database: 0
# timeout: 60For more advanced configuration, create a LettuceConfig bean and register it with Ebean:
LettuceConfig config = new LettuceConfig();
config.setServer("redis.example.com");
config.setPort(6379);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setService(config);Or provide your own Redis client instance:
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setService(redisClient);The library implements a near cache pattern to improve read performance for frequently accessed data. Near cache invalidation is handled automatically through Redis pub/sub.
Metrics are collected for:
- Query cache operations
- Table modification events
- Near cache operations
Configure logging levels for detailed insight:
<logger name="io.ebean.cache" level="TRACE"/>
<logger name="io.ebean.cache.QUERY" level="TRACE"/>
<logger name="io.ebean.cache.BEAN" level="TRACE"/>
<logger name="io.ebean.cache.COLL" level="TRACE"/>
<logger name="io.ebean.cache.NATKEY" level="TRACE"/>