【发布时间】:2022-08-21 07:31:20
【问题描述】:
我想在 SPring Boot EH Cache 应用程序中设置一个不会过期的缓存。
我想根据应用程序参数重新加载缓存。我该如何实施?
我可以看到有一个TimeToLiveinMinutes 参数。我应该增加那个值,如果是的话,我可以给那个值多少最大值。请建议。
标签: spring-boot caching ehcache
我想在 SPring Boot EH Cache 应用程序中设置一个不会过期的缓存。
我想根据应用程序参数重新加载缓存。我该如何实施?
我可以看到有一个TimeToLiveinMinutes 参数。我应该增加那个值,如果是的话,我可以给那个值多少最大值。请建议。
标签: spring-boot caching ehcache
如果您不指定生存时间,则条目不会过期。例如,具有以下配置的缓存中的条目不会过期:
<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-expiring 和 expiring 缓存的示例工作应用程序。
【讨论】: