Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

How to sync an operation between Redis and MongoDB

$
0
0

I'll try to keep my question short and simple.

Say, I have a Springboot application that allows creation of a certain entity with Time to live. I store the entity in a MongoDB. When a request comes to get the entity, the application fetches it from DB, caches it in Redis and sends the response. Next consecutive requests will be served from the cache

When the TTL (which is configurable and is determined at the time of creation of the entity) of the entity expires, it's going to be removed from the MongoDB.

I am having trouble figuring out how to sync that with the Redis cache. I was thinking that at the time of the first query when I am caching the response, I would cache it with the remaining TTL of the entity, so that I don't have to do anything extra to remove it from both Mongo and Redis. Both Redis and Mongo will take care of the removal on their own. Currently, I cache responses using the @Cacheable annotaion, but I couldn't find out any extra parameter in that annotation that will dynamically set a TTL.

Is there a way to achieve it keeping the @Cacheable annotation on my method?


Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>