Java EhCache溢出到特定路径的磁盘

Java EhCache溢出到特定路径的磁盘,java,hibernate,ehcache,Java,Hibernate,Ehcache,我在我的应用程序中使用带有hibernate的ehcache。 下面是ehcache.xml的配置 <ehcache> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10" eternal="false" timeToIdleSeconds="120"

我在我的应用程序中使用带有hibernate的ehcache。 下面是ehcache.xml的配置

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

    <defaultCache
            maxElementsInMemory="10"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="300"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
</ehcache>


我的diskStore路径是java.io.tmpdir,我想将其更改为我的应用程序路径${WebApp}/diskStore

存储位置由硬涂层路径指定

路径attibute的合法值是合法的文件系统路径

例如,对于Unix:/home/application/cache

以下系统属性也是合法的,在这种情况下,它们被转换为:

user.home - User's home directory
user.dir - User's current working directory
java.io.tmpdir - Default temp file path
ehcache.disk.store.dir - A system property 
可以在系统属性下指定子目录,例如:

java.io.tmpdir/one

在Unix系统上变为:


/tmp/one

也可以使用编译时将被替换的属性。因此,您需要正确配置pom.xml,例如

<build>
    <filters>
        <filter>${user.home}/my.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

${user.home}/my.properties
src/main/resources
真的

(至少这是我们项目的工作环境)

我最近尝试了ehcache,想知道什么是
java.io.tmpdir
以及它在我的机器上的位置。这一页中被接受的答案并没有解决我的问题。我选中了
/tmp
,但找不到ehcache文件

以下是我在网上找到的,希望对其他人有所帮助:

1.在终端上运行
env
命令。它打印操作系统环境。就我而言,它给了我:

TMPDIR=/var/folders/1j/pb3h7\u hl7890px72\u f8mntd00000gn/T/

2.或者,您可以从python控制台查询:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.gettempdir()
'/var/folders/1j/pb3h7_hl7890px72_f8mntd00000gn/T'
给你

user.home->它是用户主目录e.i C:\Users\abc(windowdrive:\Users\username) user.dir->C:\Users\abc\eclipse workspace\project java.io.tmpdir->C:\Users\abc\AppData\Local\Temp\ ehcache.disk.store.dir-系统属性()

如需更多帮助,请随时通过电子邮件进行交流_sh@yahoo.com


谢谢

我相信@Pradeep应该得到一个公认的答案。我们有windows server。通过指定绝对路径,它是有效的。有什么方法可以通过代码或webApp的相对路径来动态指定路径吗?我相信在Java类中,我们可以读取应用程序根目录,但这里需要在xml文件中执行此操作。因此,我不确定是否有动态值替换。默认临时文件路径windows
C:\Users\user\AppData\Local\temp