为什么以下 ehcache.xml 不允许通过 JMX 清除缓存(在 JVisualVM for MBean 中禁用了"操作"选项卡以进行缓存管理,并为缓存统计信息启用了(?我使用 spring boot 框架并通过 spring.cache.jcache.config 属性指定 ehcache.xml 文件位置,并且只使用 spring@Cachable框架注释。
<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 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">
<service>
<jsr107:defaults enable-management="true" enable-statistics="true"/>
</service>
<cache alias="stringCache">
<key-type>java.lang.String</key-type>
<value-type>java.lang.String</value-type>
<heap unit="entries">2000</heap>
</cache>
</config>
JSR-107 规范不支持清除高速缓存条目。只能清除统计信息。要解决此问题,您必须创建自己的 MBean。