rohanagarwal rohanagarwal - 1 month ago 17
Java Question

Cache and Spring

I want to know about some cache libraries to be used with spring. I want the cache to be centralised distributed as I have multiple servers.This also rules out guava(in-memory cache). Redis/Jedis and Couchbase are two options but with lacking support for java. They need all java objects/beans to be serializable. Guava supports java but is in-process. Redisson seems good but I read that it lacks support and maintenance compared to Jedis.

I want to prevent code changes to a great extent, and thus don't want my beans to implement Serializabe, neither do I want to convert my objects to Json or Strings.

Answer

For me your requirements are contrary to each other. You need to choose one of

  1. No serialization of any kind. But that works only for cache in single JVM.
  2. Distributed cache. Data stored outside of application JVM. Possible to many nodes. But that requires serialization of some kind. Be it java serialization, JSON, Arvo, Kryo, Parquet, protocollBuffers.. Data be transfered over the network in serialized form.

No matter what you choose, http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html will help you. It has support for

  • JDK ConcurrentMap-based Cache
  • Ehcache-based Cache
  • Caffeine Cache
  • Guava Cache
  • GemFire-based Cache
  • JSR-107 Cache

Why you believe that Redis/Jedis and Couchbase are lacking support for java? They have very good support, but your objects must be serialized.

For Redis, it is supported as cache abstraction by http://docs.spring.io/spring-data/redis/docs/1.7.4.RELEASE/reference/html/#redis:support:cache-abstraction

Similar project exist for Couchbase https://github.com/couchbaselabs/couchbase-spring-cache