首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ehcache 3统计信息spring boot

ehcache 3统计信息spring boot
EN

Stack Overflow用户
提问于 2018-01-18 03:36:28
回答 1查看 2.2K关注 0票数 0

我通读了ehcache3的文档,它在spring缓存的上下文中有点令人困惑。我的配置如下:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<ehcache:config updateCheck="true"
	monitoring="autodetect"
	dynamicConfig="true"
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
  xmlns:ehcache='http://www.ehcache.org/v3'
  xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
  xsi:schemaLocation="
  http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd 
  http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.1.xsd">
<ehcache:annotation-driven />
<ehcache:service> 
  <service>
    <jsr107:defaults enable-management="true" enable-statistics="true"/> 
  </service>
 </ehcache:service>

  <ehcache:cache alias="xyz" statistics="true">
    <ehcache:key-type>java.lang.Long</ehcache:key-type>
    <ehcache:value-type>a.b.c.something</ehcache:value-type>
    <ehcache:expiry>
    	<ehcache:ttl unit="seconds">10</ehcache:ttl>
    </ehcache:expiry>
    <ehcache:resources>
      <ehcache:heap unit="entries">10000</ehcache:heap>
      <ehcache:offheap unit="MB">1</ehcache:offheap>
    </ehcache:resources>
    <jsr107:mbeans enable-statistics="true"/>
  </ehcache:cache>
  ...
  </ehcache:config>

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

我的yaml:

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

对于我应该寻找的东西,我有点迷失了--我以为org.ehcache可以被剖析出来,并且会出现。我在jvisualvm中看不到有这种模式的任何东西。或者不确定如何读取信息。在ehcache2.x中曾经很简单,任何帮助都将不胜感激。我想知道缓存的大小和数量。缓存中当前元素的数量等。

EN

回答 1

Stack Overflow用户

发布于 2018-01-19 02:26:18

要确定如何回答,需要spring配置和一些Java代码。然而,您当前的ehcache.xml似乎是Ehcache2和Ehcache3的奇怪混合体,而且yaml是错误的。

因此,您需要一个包含JSR-107的pom.xml

代码语言:javascript
复制
    <dependency>
        <groupId>javax.cache</groupId>
        <artifactId>cache-api</artifactId>
    </dependency>

    <dependency>
        <groupId>org.ehcache</groupId>
        <artifactId>ehcache</artifactId>
        <version>3.4.0</version>
    </dependency>

application.yml应该有一个spring前缀。

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

要启用缓存,您需要@EnableCaching<cache:annotation-driven/>之类的东西,它们应该在Spring配置中,而不是在ehcache.xml中。

最后,我清理了不应该出现在ehcache.xml中的所有内容。我还使用了一个默认的名称空间,使其更具可读性。此外,由于Spring缓存是无类型的,您需要从缓存配置中删除key-typevalue-type

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                xmlns='http://www.ehcache.org/v3'
                xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
                xsi:schemaLocation="
  http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd
  http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.1.xsd">

  <service>
      <jsr107:defaults enable-management="true" enable-statistics="true"/>
  </service>

  <cache alias="xyz">
    <expiry>
      <ttl unit="seconds">10</ttl>
    </expiry>
    <resources>
      <heap unit="entries">10000</heap>
      <offheap unit="MB">1</offheap>
    </resources>
    <jsr107:mbeans enable-statistics="true"/>
  </cache>

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

https://stackoverflow.com/questions/48308705

复制
相关文章

相似问题

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