Katy
Katy

Reputation: 1157

@Cacheable And @CachePut on the same method with opposite condition

Is it possible to use @CachePut and @Cacheable in conjonction on the same method?

@CachePut(value ="cacheName", key = "#id", condition="#cachedData==false")
@Cacheable(value ="cacheName", key = "#id", condition="#cachedData==true")
public Foo doSomthing(String id, boolean cachedData){...}

Upvotes: 0

Views: 1477

Answers (1)

Mo_-
Mo_-

Reputation: 634

I think you can use @Caching to group multiple caching annotations to implement a customised logic.

Maybe something like:

@Caching(
            put= { @CachePut(value="cacheName", key="#id", condition="#cachedData==false") },
            cacheable = { @Cacheable(value ="cacheName", key="#id", condition="#cachedData==true") }
)
public Foo doSomething(String id, boolean cachedData){...}

Upvotes: 2

Related Questions