This release provides support for server-assisted, client-side caching, and is currently beta grade.
Client-side caching is available within UnifiedJedis, JedisPooled, JedisCluster, etc classes via implementation of ClientSideCache class, with RESP3 only. It is recommended a ClientSideCache implementation with TTL (time-to-live). We have included two implementations based on Google Guava and Caffeine libraries.
class CacheExample {
public static void main() {
HostAndPort node = HostAndPort.from("localhost:6379");
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
.resp3() // RESP3 protocol
.password("foobared")
.build();
ClientSideCache clientSideCache;
// GuavaClientSideCache clientSideCache = GuavaClientSideCache.builder().maximumSize(1000).ttl(100).build();
// CaffeineClientSideCache clientSideCache = CaffeineClientSideCache.builder().maximumSize(1000).ttl(100).build();
UnifiedJedis client = new UnifiedJedis(node, clientConfig, clientSideCache);
// JedisPooled client = new JedisPooled(node, clientConfig, clientSideCache);
// JedisCluster client = new JedisCluster(Collections.singleton(node), clientConfig, clientSideCache);
client.set("foo", "bar");
client.get("foo");
client.get("foo"); // cache hit
client.del("foo");
client.close();
}
}