使用grails3的ehcache3插件的有效ehcache.xml

问题描述 投票:0回答:2

grails version 3.3.1 cache-ehcache:3.0.0.M1

有人可以给我发一个有效的ehcache.xmlplease吗?

我的文件看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="ehcache.xsd"
     updateCheck="true"
     monitoring="autodetect"
     dynamicConfig="true">

    <diskStore path="java.io.tmpdir"/>

    <cache name="sevenSeconds"
       maxEntriesLocalHeap="100"
       maxEntriesLocalDisk="1000"
       eternal="false"
       timeToLiveSeconds="7"
       timeToIdleSeconds="0"
       memoryStoreEvictionPolicy="LFU"
       transactionalMode="off">
       <persistence strategy="localTempSwap" />
    </cache>

    <defaultCache
        maxElementsInMemory="50000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="true"
        diskPersistent="false"
        diskExpiryThreadIntervalSeconds="120"
        memoryStoreEvictionPolicy="LRU"
    />
</ehcache>

我在启动时遇到此错误:

Caused by: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/home/user/workspaces/api2-grails/grails-app/conf/ehcacheCustom.xml
Caused by: org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of element 'ehcache'.

谢谢你的建议

grails3 ehcache-3
2个回答
0
投票

自从ehcache 3.0.0以来,xml格式发生了变化。这是我的基础版本:

<?xml version="1.0" encoding="UTF-8"?>       
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="ehcache-core.xsd">
    <persistence directory="java.io.tmpdir"/>
    <cache alias="twentySeconds">
        <expiry>
            <ttl unit="seconds">20</ttl>
        </expiry>
        <heap>2</heap>
    </cache>
</config>

0
投票

在遇到同样的问题后,我找到了这个link,并把它作为基础来获得以下工作示例:

<ehcache:config xmlns:ehcache="http://www.ehcache.org/v3" xmlns:jcache="http://www.ehcache.org/v3/jsr107">
    <ehcache:cache alias="books">
        <ehcache:key-type>java.lang.String</ehcache:key-type>
        <ehcache:value-type>hello.Book</ehcache:value-type>
        <ehcache:resources>
            <ehcache:heap unit="MB">1</ehcache:heap>
            <!--ehcache:offheap unit="MB">10</ehcache:offheap-->
        </ehcache:resources>
    </ehcache:cache>
</ehcache:config>
© www.soinside.com 2019 - 2024. All rights reserved.