@Cacheable 和@CachePut 在相同的方法上但条件相反

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

是否可以在同一方法中结合使用 @CachePut@Cacheable

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

我认为你可以使用@Caching将多个缓存注释分组来实现自定义逻辑。

可能是这样的:

@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){...}