1

I have used spring @Cacheable for caching as shown below:

@Cacheable
public Response mycall(Request request)

Now I want this method call to be cached only if request.getId()!=3, where getId() is a public getter method in Request class.

I have seen code wherein people have specified unless condition in @Cacheable, but I have seen conditions being specified only on Response of the method and not on Request. Reference: How do I tell Spring cache not to cache null value in @Cacheable annotation

Is there any way to achieve the same with condition being specified on a field of the request

Manas Saxena
  • 2,171
  • 6
  • 39
  • 58

1 Answers1

0

Did you try the condition attribute?

//It will cache only if the actor's age is more than 20. Here actor is the input parameter.
@Cacheable(value="movies", key="#actor.name", condition="#actor.age > 20")
public List<movie> getMovies(Actor actor) ...

See ttps://www.codelooru.com/2017/03/spring-cache-part-3-conditional-cache.html

Mahatma_Fatal_Error
  • 720
  • 1
  • 10
  • 26