apache shiro - session is lost when the server restarts? - spring

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?

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?

Setting up RMI ehcache replication with proper multicast address setting

I am using replication with RMI type
I have ehcache replication working when when both cache nodes are on same hosts.
But problem arises when i have two different host in same domain, replication fails.
One cache node on windows 8 and other cache node on CentOS 6.
I am not sure what settingsneed to done for multicast to be enabled on Linux box.
I also tried with manual discovery but the program just stuck.
ehcache.xml snippet:
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" properties="hostName=10.30.10.439, port=40001, socketTimeoutMillis=2000"/>
<defaultCache
maxBytesLocalHeap="256000000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<!-- temp config: in memory cache, expire after the session is idle for 10 minutes -->
<cache name="ssoSessionStore"
maxBytesLocalHeap="64000000"
eternal="false"
timeToIdleSeconds="600"
timeToLiveSeconds="0"
overflowToDisk="false"
maxElementsOnDisk="20000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<cacheEventListenerFactory
class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicateAsynchronously=true
asynchronousReplicationIntervalMillis=100"
propertySeparator=","
/>
<bootstrapCacheLoaderFactory
class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory"
properties="bootstrapAsynchronously=true, maximumChunkSizeBytes=5000000"
propertySeparator="," />
</cache>
Similar ehcache.xml I configure on other node with different IP address keeping multicast address same.
I am not sure what settings i am missing .
Please suggest.

How to clear a specific cache region : ehcache

I have a ehcache configuration like the below :
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cache
name="reg1"
maxElementsInMemory="100000"
eternal="false"
overflowToDisk="true"
timeToLiveSeconds="1">
</cache>
<cache
name="reg2"
maxElementsInMemory="1000000"
eternal="false"
overflowToDisk="true"
timeToLiveSeconds="100"/>
</ehcache>
I am unable to figure out how I can clear just "reg1".
I have seen a method to clear all but not a specific region.
Anyone who has figured out how to do this, please share.
Thanks
From the Ehcache documentation :
http://ehcache.org/apidocs/2.4.4/net/sf/ehcache/Cache.html#removeAll()
Removes all cached items.

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