【问题标题】:Infinispan 2LC : entity cache with regions specified in query cacheInfinispan 2LC:在查询缓存中指定区域的实体缓存
【发布时间】:2017-10-03 16:57:19
【问题描述】:

我有一个entity A,它被定义为@Cacheable。我有查询缓存加载指定缓存区域下的entity A 说“regionA”。这是通过setHint 和启用缓存来完成的。

至于wildfly中的设置,regionA配置为没有evictionexpiration为1天,而entity缓存默认evictionexpiration如下.

        <local-cache name="entity">
            <transaction mode="NON_XA"/>
            <eviction strategy="LRU" max-entries="10000"/>
            <expiration max-idle="1000000"/>
        </local-cache>
        <local-cache name="local-query">
            <eviction strategy="LRU" max-entries="10000"/>
            <expiration max-idle="100000"/>
        </local-cache>
        <local-cache name="regionA" statistics-enabled="true">
            <eviction strategy="NONE" max-entries="-1"/>
            <expiration lifespan="86400000" max-idle="14400000"/>
        </local-cache>

现在,如果我第一次执行,没有查询缓存结果,因此运行 SQL 来获取实体。后来第二次运行,第三次似乎是从缓存regionA 中取出的,因此没问题。但在 18 小时后,我尝试运行相同的查询,看起来查询再次运行。

但我想如果查询缓存配置为“1天”到期,为什么它会再次运行SQL?是因为entity 缓存到那时就过期了吗?所以entity 缓存不采用缓存区域特定设置? 如何区分存储在特定缓存区域中的这些实体遵循区域特定设置。

谢谢。

【问题讨论】:

    标签: infinispan wildfly-10 second-level-cache


    【解决方案1】:

    你有max-idle="14400000",这意味着如果过去4小时内没有执行查询,缓存的结果就会过期。

    【讨论】:

    • 感谢您的发现。那么有没有办法指定实体使用 regionA 缓存配置并将它们存储在指定的缓存区域中?因为默认情况下,每个实体都在自己的区域下创建。
    • 您需要使用 Hibernate 的 org.hibernate.annotation.Cache 来定义区域。或者通过orm.xml在外部设置。
    • 谢谢我知道了。因此,使用 hibernate.cfg,我可以将所有实体配置为使用指定区域,也可以将每个实体配置为使用指定区域。但是不可能只指定查询中引用的实体,其缓存区域为 regionA。对吗?
    • IIUC your q - 不,每个实体将始终根据其类型在缓存/区域中结束。无法配置使用查询加载的那些最终会出现在用于查询本身的区域(或任何其他提示区域)中。
    • 谢谢你的解释。
    猜你喜欢
    • 2023-03-24
    • 2016-09-20
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2013-02-11
    • 2011-01-25
    相关资源
    最近更新 更多