0

I have a requirement to cache some static data as it is being consumed by our system. There is a static API that gives a map of records and we are fetching the corresponding record based on request.

Instead of calling the static API for every request, we are planning on caching the data in an in-memory Java cache that spring boot provides an calling the API only if the key is missing.

Cache implementation can be any one of these, https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/boot-features-caching.html#boot-features-caching-provider.

We have multiple containers deployed for our application and the pods can go down to create new ones taking down the cache with it. What I'm wondering is if using a Spring Boot cache a good choice here or is it better to go with some central caching service like redis?

2 Answers 2

0

Spring Boot cache is just a way to use @Cacheable as a fast way to integrate it in your code. So you will have a Cache Provider implementing it behind the curtains. With a kubernetes multipod app you will surely want to keep a distributed implementation so that the data does not die with the pod. (This rules out some nice implementations like Caffeine)

Mi personal experience has been with Redis and a little bit of Hazelcast. Both should be OK. As @xTheProgrammer already talked about Hazelcast let me talk about Redis.

Using the Redis Cache is a perfectly OK solution. Here there are some details about how to implement it.

The only considerations are:

  • You will need an extra shared infrastructure.(In the cloud this means money)
  • Redis is a very fast in-memory database. It is really great but RAM memory is typically expensive. Estimate the size of the cache (More size == more money).
  • As with any cache, is nice to monitor size, eviction rate, hit ratio....
0

Recently did the same in our project. Started with Hazelcast. Hazelcast brings it's own second-level-cache manager. So consider this if you are currently using ehcache together with hibernate or something similar. Right now I am using redis and it is working quite fine.

The big advantage of Hazelcast is, that you don't need a dedicated server to share the memory. The instances will synchronize themself.

1
  • Sorry I am not aware of Hazelcast. Do you think it'll solve my concern in a multi-container environment?
    – Hindol Dey
    Jul 12 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.