Имеем два кэшированных метода:
1.
2.
@Cacheable(value = CacheName.CACHE_STATIC, key="'getImageUserLayer'.concat(':').concat(#layerId)")
public byte[] getImageUserLayer(int layerId) {
и
1.
2.
3.
@Cacheable(value = CacheName.CACHE_STATIC, key="'getLastModifiedUserLayer'.concat(':').concat(#layerId)")
@Override
public String getLastModifiedUserLayer(int layerId) {
так же метод, для вычищения ключей:
1.
2.
3.
4.
5.
@Caching(evict = {
@CacheEvict(value = CacheName.CACHE_STATIC, key = "'getImageUserLayer'.concat(':').concat(#layerId)"),
@CacheEvict(value = CacheName.CACHE_STATIC, key = "'getLastModifiedUserLayer'.concat(':').concat(#layerId)")
})
public void updateLayer(UserLayer layer, int layerId) {
вызываем первые два, с разными layerId, значения кэшируются,
затем вызываем updateLayer(5510461)
и судя по логам инвалидируются и другие ключи, кроме указанного, например 4900061:
1.
2.
3.
4.
5.
6.
7.
8.
9.
2020-02-10 16:47:07.065 [http-nio-8080-exec-9] TRACE o.s.c.i.CacheInterceptor - Computed cache key 'getLastModifiedUserLayer:4900061' for operation Builder[public java.lang.String com.prognoz.smkoob.data.dao.ImageServiceImpl.getLastModifiedUserLayer(int)] caches=[cacheStatic] | key=''getLastModifiedUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
2020-02-10 16:48:32.695 [http-nio-8080-exec-7] TRACE o.s.c.i.CacheInterceptor - Invalidating cache key [getImageUserLayer:5510461] for operation Builder[public void com.prognoz.smkoob.data.dao.meta.UserLayerServiceImpl.updateLayer(com.prognoz.smkoob.domain.UserLayer.UserLayer,int)] caches=[cacheStatic] | key=''getImageUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='',false,false on method public void com.prognoz.smkoob.data.dao.meta.UserLayerServiceImpl.updateLayer(com.prognoz.smkoob.domain.UserLayer.UserLayer,int)
2020-02-10 16:48:32.701 [http-nio-8080-exec-7] TRACE o.s.c.i.CacheInterceptor - Invalidating cache key [getLastModifiedUserLayer:5510461] for operation Builder[public void com.prognoz.smkoob.data.dao.meta.UserLayerServiceImpl.updateLayer(com.prognoz.smkoob.domain.UserLayer.UserLayer,int)] caches=[cacheStatic] | key=''getLastModifiedUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='',false,false on method public void com.prognoz.smkoob.data.dao.meta.UserLayerServiceImpl.updateLayer(com.prognoz.smkoob.domain.UserLayer.UserLayer,int)
2020-02-10 16:48:33.591 [http-nio-8080-exec-4] TRACE o.s.c.i.CacheInterceptor - Computed cache key 'getLastModifiedUserLayer:5510461' for operation Builder[public java.lang.String com.prognoz.smkoob.data.dao.ImageServiceImpl.getLastModifiedUserLayer(int)] caches=[cacheStatic] | key=''getLastModifiedUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
2020-02-10 16:48:33.591 [http-nio-8080-exec-4] TRACE o.s.c.i.CacheInterceptor - No cache entry for key 'getLastModifiedUserLayer:5510461' in cache(s) [cacheStatic]
2020-02-10 16:48:33.909 [http-nio-8080-exec-3] TRACE o.s.c.i.CacheInterceptor - Computed cache key 'getLastModifiedUserLayer:4900061' for operation Builder[public java.lang.String com.prognoz.smkoob.data.dao.ImageServiceImpl.getLastModifiedUserLayer(int)] caches=[cacheStatic] | key=''getLastModifiedUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
2020-02-10 16:48:33.909 [http-nio-8080-exec-3] TRACE o.s.c.i.CacheInterceptor - No cache entry for key 'getLastModifiedUserLayer:4900061' in cache(s) [cacheStatic]
2020-02-10 16:48:33.909 [http-nio-8080-exec-8] TRACE o.s.c.i.CacheInterceptor - No cache entry for key 'getLastModifiedUserLayer:5129071' in cache(s) [cacheStatic]
2020-02-10 16:48:33.910 [http-nio-8080-exec-8] TRACE o.s.c.i.CacheInterceptor - Computed cache key 'getLastModifiedUserLayer:5129071' for operation Builder[public java.lang.String com.prognoz.smkoob.data.dao.ImageServiceImpl.getLastModifiedUserLayer(int)] caches=[cacheStatic] | key=''getLastModifiedUserLayer'.concat(':').concat(#layerId)' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
почему так, интересно?