【问题标题】:Using spring @Cacheable with a keyGenerator and unless properties使用带有 keyGenerator 和除非属性的 spring @Cacheable
【发布时间】:2021-07-14 00:15:59
【问题描述】:

使用 spring-boot 2.4.3 org.springframework:spring-context:5.3.4

我有一个使用 keyGenerator 的 @Cacheable 方法 它工作正常。 我想使用静态方法添加除非属性,但它不起作用。

注解的示例代码(不调用静态方法

@Cacheable(value = CURRENCY_CHANNELS_CACHE, keyGenerator = CURRENCY_CHANNEL_CACHE_KEY_GENERATOR, unless = "#{ T(com.cache.MyCacheKeyGenerator).isQueryNotCacheable(#p0) }")
public List<Item> getQueryForCollection(final QueryBuilder query, final String sort)
public static boolean com.cache.MyCacheKeyGenerator.isQueryNotCacheable(final QueryBuilder query)

未被调用。我收到找不到它的错误。

【问题讨论】:

    标签: java spring-cache


    【解决方案1】:

    谢谢。现在可以了。 我没有打开弹簧的痕迹。

    【讨论】:

      【解决方案2】:

      您在 unless 参数中使用了错误的 SpEL 语法。正确的语法是:

      unless = "T(com.cache.MyCacheKeyGenerator).isQueryNotCacheable(#p0)"
      

      我在这里测试了解决方案:https://github.com/ygor-sk/stackoverflow/tree/master/q67168108-cacheable-unless-static

      下次,请提供您在问题中直接遇到的错误。这一定很明显:

      EL1043E: 意外令牌。应为“标识符”,但为“lcurly({)”

      【讨论】:

        猜你喜欢
        • 2018-11-05
        • 1970-01-01
        • 2019-01-30
        • 2020-05-03
        • 2015-05-27
        • 2012-07-08
        • 2015-09-22
        • 2015-11-26
        • 2018-02-02
        相关资源
        最近更新 更多