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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11559464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:34:04  来源:igfitidea点击:

EhCache overflow to disk at specific path

javahibernateehcache

提问by Rahul Agrawal

I am using ehcache with hibernate in my application. here is configuration of ehcache.xml

我在我的应用程序中使用 ehcache 和 hibernate。这是 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>

my diskStore path is java.io.tmpdir, which i want to change to my application path as ${WebApp}/DiskStore

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

回答by NPKR

Storage Location are specified by hard coading paths.

存储位置由硬编码路径指定。

Legal values for the path attibute are legal file system paths.

路径属性的合法值是合法的文件系统路径。

E.g., for Unix: /home/application/cache

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

The following system properties are also legal, in which case they are translated:

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

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 

Subdirectories can be specified below the system property, for example:

可以在系统属性下指定子目录,例如:

java.io.tmpdir/one

java.io.tmpdir/one

becomes, on a Unix system:

在 Unix 系统上变成:

/tmp/one

/tmp/一

回答by zazi

It is also possible to utilise a property that will be replaced on compile time. Therefore, you need to configure your pom.xml properly, e.g.

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

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

(at least this was a working setting for our project)

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

回答by Haifeng Zhang

I have tried ehcache recently and was wondering what is java.io.tmpdirand where it is located on my machine. The accepted answer in this page didnt solve my issue. I checked /tmpand the ehcache file is not found.

我最近尝试过 ehcache,想知道java.io.tmpdir它是什么以及它在我的机器上的位置。此页面中接受的答案并没有解决我的问题。我检查过/tmp,没有找到 ehcache 文件。

Here's what I find online and hope it helps to other people:

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

1.run envcommand on your terminal. It prints the OS environment. In my case, it gave me:

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

TMPDIR=/var/folders/1j/pb3h7_hl7890px72_f8mntd00000gn/T/

TMPDIR=/var/folders/1j/pb3h7_hl7890px72_f8mntd00000gn/T/

2.alternatively, you can query from python console:

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'

回答by Shahid Hussain Abbasi

Here you go.

干得好。

user.home -> It is user home directory 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 - A system property (https://www.ehcache.org/documentation/3.7/)

user.home -> 它是用户主目录 ei 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 - 系统属性 ( https://www.ehcache.org/documentation/3.7/)

For more help feel free to communicate over email [email protected]

如需更多帮助,请随时通过电子邮件 [email protected] 进行交流

Thanks

谢谢