Spring Cache: キャッシュの型が変わったらキャッシュを破棄する方法
@Configuration
@EnableCaching
public class CacheConfig implements CachingConfigurer {
@Override
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler() {
@Override
public void handleCacheGetError(
@NotNull RuntimeException exception,
@NotNull Cache cache,
@NotNull Object key) {
if (exception instanceof SerializationException) {
cache.evict(key);
return;
}
throw exception;
}
};
}
}