【问题标题】:How to set a Unexpirable cache in Sprint Boot EH Cache如何在 Spring Boot EHCache 中设置不可过期缓存
【发布时间】:2022-08-21 07:31:20
【问题描述】:

我想在 SPring Boot EH Cache 应用程序中设置一个不会过期的缓存。 我想根据应用程序参数重新加载缓存。我该如何实施? 我可以看到有一个TimeToLiveinMinutes 参数。我应该增加那个值,如果是的话,我可以给那个值多少最大值。请建议。

    标签: spring-boot caching ehcache


    【解决方案1】:

    如果您不指定生存时间,则条目不会过期。例如,具有以下配置的缓存中的条目不会过期:

    <config xmlns='http://www.ehcache.org/v3'
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
            xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                                http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
    
        <cache alias="testCache">
            <resources>
                <heap unit="entries">100</heap>
                <offheap unit="MB">10</offheap>
            </resources>
        </cache> 
    </config>
    

    而具有以下配置的缓存中的条目每 10 秒过期一次:

    
    <config xmlns='http://www.ehcache.org/v3'
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
            xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                                http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">
    
        <cache alias="testCache">
            <expiry>
                <ttl unit="seconds">10</ttl>
            </expiry>
    
            <resources>
                <heap unit="entries">100</heap>
                <offheap unit="MB">10</offheap>
            </resources>
        </cache> 
    </config>
    

    您可以在 github 上找到 non-expiringexpiring 缓存的示例工作应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2017-02-22
      • 2013-04-23
      • 1970-01-01
      相关资源
      最近更新 更多