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

How to achieve the following behavior by using the @Cacheable annotation?

$
0
0

Let's assume that I have a method that fetches data from Mongo which can be cached into redis.

@Cacheablepublic List<Values> cacheValues(List<String> input){     // code that fetches the list based on input from mongodb}

The problem is that there is a list of documents that corresponds to each particular input in mongo db. When fetched from mongo, all lists are merged into a single list. Is there any way we can tell the @Cacheable annotation that data has to be persisted and fetched in the same way? or is there any way we can customize the @Cacheable to be able to use our own redis operations for fetching and persisting?. I am using spring data redis.

2nd question: How can I create a key based the values in input. For example:

@Cacheable(cacheNames = "cach1", key = "input[0] +…. input[input.size-1]")        public List<Values> cacheValues(List<String> input){             // code that fetches the list based on input from mongodb        }

Viewing all articles
Browse latest Browse all 2204

Trending Articles



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