首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Spring Boot使Ehcache TTL超时可配置

使用Spring Boot使Ehcache TTL超时可配置
EN

Stack Overflow用户
提问于 2019-03-04 09:45:08
回答 1查看 1.5K关注 0票数 1

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

我当前的应用程序属性:

代码语言:javascript
复制
spring.cache.jcache.config=classpath:ehcache.xml

我的ehcache.xml:

代码语言:javascript
复制
<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>

主类:

代码语言:javascript
复制
@SpringBootApplication
@EnableCaching
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
}

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

EN

回答 1

Stack Overflow用户

发布于 2019-03-04 23:19:31

我认为您可以切换到编程配置,并实现一个新的属性类,就像他们为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之类的框架或最终用户都可以。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54975613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档