@Caching(cacheable =
{
@Cacheable(cacheManager = "localCacheManager"),
@Cacheable(cacheManager = "redisCacheManager"),
}
)
I can implement a memory hierarchy using @Caching as shown in the code above. However, the problem is that the criterion for a cache hit in CacheAspectSupport is when at least one of the @Cacheable's is a cache hit. Conversely, a cache miss is determined when all @Cacheable's are cache misses.
The code below is part of the 'execute' method of the CacheAspectSupport class, which relates to the aforementioned issue.
// Check if we have a cached item matching the conditions
Cache.ValueWrapper cacheHit = findCachedItem(contexts.get(CacheableOperation.class));
// Collect puts from any @Cacheable miss, if no cached item is found
List<CachePutRequest> cachePutRequests = new ArrayList<>();
if (cacheHit == null) {
collectPutRequests(contexts.get(CacheableOperation.class),
CacheOperationExpressionEvaluator.NO_RESULT, cachePutRequests);
}
For example, let's think about a case where a certain key is a miss in the first cache but a hit in the second cache. This key will always result in a hit in the second cache unless it's cached in the first cache. Since it's a hit in the second cache, it ultimately results in a cache hit. The problem here is that there's no way to synchronize the first and second caches due to the ultimate cache hit.
What I want to do is to synchronize the cached value of the first cache, where the miss occurred, with the second cache when a hit occurs in the second cache. However, I currently don't have a good method to do this. Can you suggest a good solution
Comment From: snicoll
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.