gpt4 book ai didi

java - 使用 Spring Boot 配置 Ehcache TTL 超时

转载 作者:行者123 更新时间:2023-12-02 10:11:27 24 4
gpt4 key购买 nike

如何通过常规 Spring Boot application.properties/application.yml 来配置 Ehcache 生存时间过期时间?

我当前的应用程序属性:

spring.cache.jcache.config=classpath:ehcache.xml

我的ehcache.xml:

<config xmlns:jsr107='http://www.ehcache.org/v3/jsr107' xmlns='http://www.ehcache.org/v3'>
<service>
<jsr107:defaults enable-management="true" enable-statistics="true"/>
</service>
<cache alias="Ttl" uses-template="ttl-template"/>
<cache-template name="ttl-template">
<expiry>
<ttl unit="minutes">6</ttl>
</expiry>
<resources>
<heap>10000</heap>
</resources>
</cache-template>

主类:

@SpringBootApplication
@EnableCaching
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

有没有办法让这 6 分钟可配置,以便我可以在运行时/启动时覆盖设置?对于大多数其他 Spring Boot 集成,会有一些属性允许直接覆盖配置。

最佳答案

我认为您可以切换到编程配置并实现一个新的 Properties 类,就像他们为 Jhipster 所做的那样:https://www.jhipster.tech/common-application-properties/

通过这个类,他们允许用户在 Spring 配置中设置 TTL,然后您可以自己以编程方式配置您的缓存管理器; see this example from the ehcache3-samples repo .

Spring/Spring boot 使用它们自己的缓存抽象 ( Spring Cache, fully compliant with the JSR-107 spec ),所以我认为它们的作用不是提供与 Ehcache3 实现的进一步集成; JHipster 等框架或最终用户都可以。

关于java - 使用 Spring Boot 配置 Ehcache TTL 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54975613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com