ehcache diskStore is not working - spring

my directory of ehcache is not been created whe I set the property . I am using ehcache-core 2.6.9 and hibernate-ehcache 4.0.1.Final
<?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="/tmp/ehcacheApp1" />
<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="0" timeToLiveSeconds="1800" diskSpoolBufferSizeMB="80"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>
<cache name="blockiscsi" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="5" timeToLiveSeconds="10">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxEntriesLocalHeap="5000" eternal="true">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>
update: I also tried this: <diskStore path="user.dir/ehcache" />
I received this log:
17:53:31.232 [main] WARN net.sf.ehcache.DiskStorePathManager - diskStorePath '/tmp/ehcache' is already used by an existing CacheManager either in the same VM or in a different process.
The diskStore path for this CacheManager will be set to /tmp/ehcache/ehcache_auto_created1431805507138728176diskstore.
To avoid this warning consider using the CacheManager factory methods to create a singleton CacheManager or specifying a separate ehcache configuration (ehcache.xml) for each CacheManager instance.

try with SingletonEhCacheProvider setting this
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheP‌​rovider</property>

Related

Share secondary cache accross different applications

We are using a CMS with secondary cache enabled:
Application.cfc
<cfset THIS.ormsettings.secondarycacheenabled = true />
<cfset THIS.ormsettings.cacheprovider = "ehcache" />
<cfset THIS.ormsettings.cacheConfig="ehcache.xml" />
ehcache.xml
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="true"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
The entities are set to cacheuse="transactional" like so <cfcomponent persistent="true" entityname="news" table="mews" cacheuse="transactional">
Saving an article in the CMS works great and it instantly reflects changes after saving.
One of the sites which is managed by this CMS should share the cache with the CMS. Otherwise the application reflects the changes only after timeout value set in the site's ehcache.xml:
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1800"
timeToLiveSeconds="1800"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
Is it possible to share the cache between two different applications? Would it be possible to configure this in the two Application.cfc's?

apache shiro - session is lost when the server restarts?

I'm using Apache Shiro Security.
My settings ehcache.xml
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>
<cache name="shiro-activeSessionCache"
maxElementsInMemory="10000"
overflowToDisk="true"
eternal="true"
timeToLiveSeconds="0"
timeToIdleSeconds="0"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="600"/>
EHCache Session Cache Configuration
I use these settings on two different Tomcats. I do restart the server, the first sessions are saved, the second is not. What could it be?

Ehcache Manager

I have an application that use JDBCTemplate and Hibernate.
Both of this configure to use ehcache but exception thrown:
org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
JDBCTemplate configured using spring xml
Hibernate configured using hibernate.cfg.xml
Please help.
I tried to disable the default cache in ehcache.xml but failed and i have the shared property set to true which also caused fail.
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false">
<diskStore path="java.io.tmpdir" />
<!--<defaultCache eternal="true" maxElementsInMemory="50000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="0" memoryStoreEvictionPolicy="LRU"
/>
-->
<cache name="genericDao" eternal="false" maxElementsInMemory="50000"
overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />
<cache name="reportDao" eternal="false" maxElementsInMemory="50000"
timeToIdleSeconds="28800" timeToLiveSeconds="28800"
overflowToDisk="false" memoryStoreEvictionPolicy="LFU" />
</ehcache>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="WEB-INF/ehcache/ehcache.xml"></property>
<property name="shared" value="true"></property>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache"></property>
</bean>
How to provide unique name in this case ?
Thanks.
Create two ehcache.xml configuration with different names.

ehcache diskStore location and access

I am using following configuration. I could like to see the cache file and see access the data from textpad/noteoad? is that possible? is there i can verify the data in Cache?
<cache name="cDBResponse" eternal="false"
maxElementsInMemory="100" overflowToDisk="false" diskPersistent="false"
timeToIdleSeconds="0" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory class="com.optumhealth.authorization.service.MyCacheEventListenerFactory"/>
</cache>
You should at least set diskPersistent="true" and check the location of the default diskstorage :
by default it's defined in this node
<diskStore path="java.io.tmpdir"/>
where java.io.tmpdir will depend on your OS

How to disable the Ehcache update checker?

12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [http://ehcache.org/news.html]
How do I suppress ehcache checking for new update(s), this is happening while loading my j2ee application and when ehcache is getting initialized.
One way is to place a ehcache.xml file on your classpath with the attribute updateCheck="false" in the root tag.
For example:
<ehcache updateCheck="false">
<defaultCache
maxElementsInMemory="0"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
diskPersistent="false"/>
</ehcache>
Another way is to set an environment variable:
System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
simply put, in your ehcache.xml configuration file, make sure you disable the updateCheck :
<ehcache updateCheck="false">
<defaultCache
maxElementsInMemory="0"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
overflowToDisk="false"
diskPersistent="false"
/>
</ehcache>

Resources