简体   繁体   English

如何告诉Spring Cache在@Cacheable注释中缓存异常?

[英]How do I tell Spring Cache to cache the exceptions in @Cacheable annotation?

I need 3 separate caches: 我需要3个独立的缓存:

  • Response with some data 回应一些数据
  • Null 空值
  • Exception 例外

I've already defined the two caches 我已经定义了两个缓存

@Caching(cacheable = {
    @Cacheable(value = "SomeCache", key = "#a1", unless = "#result == null"),
    @Cacheable(value = "SomeNullCache", key = "#a1", unless = "#result != null")})

So, I have to implement the last case. 所以,我必须实施最后一个案例。

JSR-107 provides @CacheResult annotation with exceptionCacheName attribute, but how can I do this using Spring Cache? JSR-107提供带有exceptionCacheName属性的@CacheResult注释,但是如何使用Spring Cache执行此操作? I don't want to combine JSR-107 and Spring Cache. 我不想将JSR-107和Spring Cache结合起来。

The cache abstraction does not support caching exception throw by annotated method. 缓存抽象不支持通过带注释的方法缓存异常抛出。 Your setup looks very weird to me. 你的设置看起来很奇怪。 Why would you use two different regions for null and non-null values? 为什么要将两个不同的区域用于null和non-null值?

Use the standard annotation if you want such setup. 如果需要这样的设置,请使用标准注释。

I don't want to combine JSR-107 and Spring Cache. 我不想将JSR-107和Spring Cache结合起来。

The id generation being different (to be spec compliant and keeping backward compatibility), I wouldn't recommend such usage. id生成不同(符合规范并保持向后兼容性),我不推荐这样的用法。 At least not on the same region. 至少不在同一地区。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Cache中的@Cacheable将值存储在cache外部的redis中。 如何将它放入Redis的缓存中? - @Cacheable in Spring Cache Stores value in redis outside cache . How do i put it inside cache in redis? 如何使用 Spring 的 @Cacheable 和 Aerospike 作为缓存? - How do I use Spring's @Cacheable with Aerospike as the cache? Spring 缓存配置到变量 int 作为 @Cacheable 注释中的键 - Spring Cache configuration to variable int as key in @Cacheable annotation 如果为@Cacheable调用缓存,则为Spring日志 - Spring log if cache is called for @Cacheable @Cacheable 命中的 Spring 缓存日志记录 - Spring cache logging on @Cacheable hit org.springframework.data.domain.PageImpl 无法反序列化,当我想使用带有注释 @Cacheable(spring cache) 的 findAll(Pageable pageable) 时? - org.springframework.data.domain.PageImpl can't be deserialized,when i want to use findAll(Pageable pageable) with annotation @Cacheable(spring cache)? 缓存刷新显示带有@cacheable注释的错误 - Cache refresh is showing error with @cacheable annotation 调用使用@Cacheable注释的方法(org.springframework.cache.annotation.Cacheable) - Calling a method annotated with @Cacheable (org.springframework.cache.annotation.Cacheable) 如何防止在spring cacheable中更改缓存的返回值 - how to prevent a return value from cache to be changed in spring cacheable @Cacheable通过Spring aop - 如何生成唯一的缓存密钥 - @Cacheable via Spring aop - how generate unique cache key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM