EhCache overflow to disk at specific path
Asked Answered
A

4

9

I am using ehcache with hibernate in my application. here is configuration of 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

Anticathode answered 19/7, 2012 at 11:3 Comment(1)
I believe @Pradeep deserves an accepted answer.Wegner
C
12

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

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

becomes, on a Unix system:

/tmp/one

Chrysa answered 19/7, 2012 at 11:17 Comment(3)
We have windows server. By specifying absolute path it is works. Is there any way we can specify path dynamically through code or relative path from webApp ?Anticathode
I believe in Java class we can read the application root directory, but here you need to do this in xml file. so i am not sure there is a replacement by dynamic value.Chrysa
java.io.tmpdir - Default temp file path windows C:\Users\user\AppData\Local\TempComplicity
P
1

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.

<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)

Priapic answered 19/6, 2013 at 14:42 Comment(0)
D
1

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

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

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

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

2.alternatively, you can query from python console:

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'
Deemster answered 3/11, 2016 at 18:30 Comment(0)
S
0

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/)

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

Thanks

Swink answered 30/4, 2019 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.