Spring cache implementation with Elasticsearch

Viewed 1228

I've got a service that is distributed between 9 VMs. I want to create a single cache that will be used between all of them. up until now I was using separate cache for each VM which gave me inconsistency between all of them.

I already have an elasticsearch that I am using so I was wondering if I can use the ES as a cache layer + spring cache abstraction together.

the service is in Java 8 + Spring Boot + ES 5.2.2


edit:

additional information, the original problem for my service is that I need to return a response in less then 100ms , that is when I've started using a simple spring cache implementation using ConcurrentCacheManager , works just fine for the speed, and the cache should be refreshed every hour~, for now I've got about 1300~ objects that needs to be cached, so on every service startup i have a process that fills the cache with all the responses that I've got and another process that would wake up every hour or so will refresh the entries with updated data. that would occur on each of the 9 vms. the issues with this system are: 1. i would hit another service multiple of 9 times each hour with all the information it got (it can handle it but it would be better if only one vm would do it) 2. if i need to update a specific entry in cache with new information or delete it all together, i don't have an issue way to remove it from all the vm's that are in my pool. 3. since each vm runs the cache refresh in a slightly different time, the cache won't be aligned across all VM's and the same call to a LB can return different results from different specific VMs. 4. for now i've got only 1300 objects that needs to be cached but it could go exponentially to millions of entries and I don't want to get stuck with out of memory issues.

I understand its not the ideal use of a cache system, and I might use a wrong term for what I want to have but basically I need a good and fast name-value storage system that can be accessed across my service. and it would be great if it can use the spring-cache abstraction because its really easy to use and it's already implemented in my service.

Thanks, A.

1 Answers

You could easily integrate Hazecast or EHCache as the distributed cache for your spring application.

It might be me, but I find it a weird choice to use Elastic Search as a cache.

Related