Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Micael Ericsson
MultiVMPool timeout settings, how?
February 28, 2014 6:26 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

I am using MultiVMPool to store some global data in our project with several portlets.

When user is idle for a while data is timeout from the cache.
The problem is that it timeout to quickly. We have a session timeout for the site set to 30 minutes.
MultiVMPool data times out in less than 10 minutes. I havn't found a specific time but it's far less than for the session.

Reading Liferay info and other forum entries I found that you can configure this, but I am unable to make this work.

First a setting in portal-ext.property is needed to point out a settings file:
ehcache.multi.vm.config.location=/liferay-multi-vm.xml

Next I configure the liferay-multi-vm.xml file.
<cache eternal="false" logging="true"
maxElementsInMemory="10000"
name="trm-cache-pool-session"
overflowToDisk="true"
timeToIdleSeconds="1800"
timeToLiveSeconds="3600"
diskPersistent="true"
diskExpiryThreadIntervalSeconds="300"
diskSpoolBufferSizeMB="10"
maxElementsOnDisk="10000000"
statistics="false"
memoryStoreEvictionPolicy="LRU"
/>

<ehcache
dynamicConfig="true"
monitoring="off"
name="liferay-single-vm"
updateCheck="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
>

<!--
Caches in this file are designed to be unique per VM and should not be
clustered.
-->

<defaultCache
eternal="false"
maxElementsInMemory="10000"
overflowToDisk="false"
timeToIdleSeconds="1800"
/>
<cache
eternal="false"
maxElementsInMemory="10000"
name="trm-cache-pool-session"
overflowToDisk="false"
timeToIdleSeconds="1800"
/>
</ehcache>

"trm-cache-pool-session" is the name of my cache pool and how it's referenced in the code.

My questions:
- Is this the right way to configure MultiVMPoolUtil cache?
- Where should I put liferay-multi-vm.xml. I have tried to put in same directory as portal-ext.properties. I don't know if this is correct and I get no feedeback on it.

liferay log has a warning and I don't know if it's related. it says:
"[localhost-startStop-1][ConfigurationFactory:284] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Portal/Liferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/webapps/ROOT/WEB-INF/lib/ehcache-core.jar!/ehcache-failsafe.xml"
I have looked and the referenced jar-file and xml-file are present at suggested path.
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
February 28, 2014 7:13 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Hi Micael,

liferay-multi-vm.xml should be in the classpath, so you should put that file in

/WEB-INF/classes
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 2, 2014 11:37 PM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Juan Gonzalez:
Hi Micael,

liferay-multi-vm.xml should be in the classpath, so you should put that file in

/WEB-INF/classes


Do I need to configure it in portal-ext.properties?
Like:
ehcache.multi.vm.config.location=/liferay-multi-vm.xml
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 3, 2014 1:06 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Micael Ericsson:

Do I need to configure it in portal-ext.properties?
Like:
ehcache.multi.vm.config.location=/liferay-multi-vm.xml


Yes, in case of having that value, it should be in /WEB-INF/classes. It would be better to change the name and/or package so it can't be compared to the default xml file.
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 3, 2014 3:54 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Juan Gonzalez:
Micael Ericsson:

Do I need to configure it in portal-ext.properties?
Like:
ehcache.multi.vm.config.location=/liferay-multi-vm.xml


Yes, in case of having that value, it should be in /WEB-INF/classes. It would be better to change the name and/or package so it can't be compared to the default xml file.


Please give me an example how you would name it.
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 3, 2014 3:56 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

For example you can add it to a custom package:

1ehcache.multi.vm.config.location=/mycache/liferay-multi-vm.xml


and then store it in /WEB-INF/classes/mycache/
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 3, 2014 5:19 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Changed package and move xml file according to above instruction.
Restarted Liferay. No exception when I start Liferay.

Logged in to my site and made selection in order to have cache to kick in.
Waited for 10 minutes.
Reloaded page and cached data was no longer cached.

Since I set 'timeToIdleSeconds="1800"' I assumed the cache would live for 30 minutes.

Suggestions on why this doesn't work?
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 4, 2014 5:00 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Is it possible to track if cache configuration is used?
Is parameter "timeToIdleSeconds" correct to use when setting timeout time for a cache?
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 4, 2014 7:05 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Micael Ericsson:
Is it possible to track if cache configuration is used?
Is parameter "timeToIdleSeconds" correct to use when setting timeout time for a cache?


Hi Micael,

seems it's getting the value for the default cache, and not the element you configured. I am not sure if this can be the cause, but your xml lacks of these lines inside <ehcache/> element:

1<cacheEventListenerFactory
2            class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory"
3            properties="replicatePuts=false,replicateUpdatesViaCopy=false"
4            propertySeparator=","
5        />
6        <bootstrapCacheLoaderFactory class="com.liferay.portal.cache.ehcache.LiferayBootstrapCacheLoaderFactory" />


How are you getting the cache?

You can increase the log levels for net.sf.ehcache
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 5, 2014 1:50 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

I tried to include the eventlistener configuration but I get the following exception in the log:
1[META-INF/util-spring.xml]: Cannot resolve reference to bean 'com.liferay.portal.kernel.cache.MultiVMPortalCacheManager' while setting bean property 'portalCacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.portal.kernel.cache.MultiVMPortalCacheManager' defined in class path resource [META-INF/util-spring.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from file:/C:/Portal/Liferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/webapps/ROOT/WEB-INF/classes/mycache/liferay-multi-vm.xml. Initial cause was Error configuring from input stream. Initial cause was null:13: Element <ehcache> does not allow nested <cacheEventListenerFactory> elements.
2    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
3    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
4    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)


This is my complete liferay-multi-vm.xml:
 1<ehcache
 2    dynamicConfig="true"
 3    monitoring="off"
 4    name="liferay-multi-vm"
 5    updateCheck="false"
 6    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 7    xsi:noNamespaceSchemaLocation="ehcache.xsd">
 8   
 9    <cacheEventListenerFactory
10            class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory"
11            properties="replicatePuts=false,replicateUpdatesViaCopy=false"
12            propertySeparator=","
13    />
14    <bootstrapCacheLoaderFactory class="com.liferay.portal.cache.ehcache.LiferayBootstrapCacheLoaderFactory" />   
15
16    <defaultCache
17        eternal="false"
18        maxElementsInMemory="10000"
19        overflowToDisk="false"
20        timeToIdleSeconds="1800"
21    />
22    <cache
23        eternal="false"
24        maxElementsInMemory="10000"
25        name="trm-cache-pool-session"
26        overflowToDisk="true"
27        timeToIdleSeconds="1800"
28    />
29</ehcache>      
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 5, 2014 2:04 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Micael Ericsson:
I tried to include the eventlistener configuration but I get the following exception in the log:
1[META-INF/util-spring.xml]: Cannot resolve reference to bean 'com.liferay.portal.kernel.cache.MultiVMPortalCacheManager' while setting bean property 'portalCacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.portal.kernel.cache.MultiVMPortalCacheManager' defined in class path resource [META-INF/util-spring.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from file:/C:/Portal/Liferay/liferay-portal-6.1.2-ce-ga3/tomcat-7.0.40/webapps/ROOT/WEB-INF/classes/mycache/liferay-multi-vm.xml. Initial cause was Error configuring from input stream. Initial cause was null:13: Element <ehcache> does not allow nested <cacheEventListenerFactory> elements.
2    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
3    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
4    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)


This is my complete liferay-multi-vm.xml:
 1<ehcache
 2    dynamicConfig="true"
 3    monitoring="off"
 4    name="liferay-multi-vm"
 5    updateCheck="false"
 6    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 7    xsi:noNamespaceSchemaLocation="ehcache.xsd">
 8   
 9    <cacheEventListenerFactory
10            class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory"
11            properties="replicatePuts=false,replicateUpdatesViaCopy=false"
12            propertySeparator=","
13    />
14    <bootstrapCacheLoaderFactory class="com.liferay.portal.cache.ehcache.LiferayBootstrapCacheLoaderFactory" />   
15
16    <defaultCache
17        eternal="false"
18        maxElementsInMemory="10000"
19        overflowToDisk="false"
20        timeToIdleSeconds="1800"
21    />
22    <cache
23        eternal="false"
24        maxElementsInMemory="10000"
25        name="trm-cache-pool-session"
26        overflowToDisk="true"
27        timeToIdleSeconds="1800"
28    />
29</ehcache>      


Hi Micael,

seems you xml is incomplete.

Please, just copy/paste the liferay-multi-vm.xml file located in portal-impl/src/ehcache and copy/paste a new <cache> entry, updating the attribute values.
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 6, 2014 12:54 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Great! Now it's working.

I replace my file with the one from portal-impl as you suggested. Added my data and viola now the cache lives for the time I want.
I also changed from MultiVMPoolUtil to SingleVMPoolUtil since we have drop any plan for cluster environment. Changed names and files accordingly.

Thanks for all help.
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 6, 2014 12:56 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Great! Now we should try to find your issue with that EJB 2 reference emoticon
Juan Gonzalez
RE: MultiVMPool timeout settings, how?
March 6, 2014 12:58 AM
Answer

Juan Gonzalez

Rank: Liferay Legend

Posts: 3036

Join Date: October 28, 2008

Recent Posts

Micael Ericsson:

I also changed from MultiVMPoolUtil to SingleVMPoolUtil since we have drop any plan for cluster environment
Thanks for all help.


Micael, in case you are using SingleVMPoolUtil, then you have to use portal-impl/src/ehcache/liferay-single-vm.xml file.
Micael Ericsson
RE: MultiVMPool timeout settings, how?
March 6, 2014 1:02 AM
Answer

Micael Ericsson

Rank: Regular Member

Posts: 138

Join Date: December 11, 2012

Recent Posts

Juan Gonzalez:
Micael Ericsson:

I also changed from MultiVMPoolUtil to SingleVMPoolUtil since we have drop any plan for cluster environment
Thanks for all help.


Micael, in case you are using SingleVMPoolUtil, then you have to use portal-impl/src/ehcache/liferay-single-vm.xml file.



I did. As I said I changed all files according to SingleVMPoolUtil instead of MultiVMPoolUtil .