Foros de discusión

"timeToIdleSeconds" secs Behavior in liferay

Suman A, modificado hace 7 años.

"timeToIdleSeconds" secs Behavior in liferay

New Member Mensajes: 9 Fecha de incorporación: 30/07/15 Mensajes recientes
Hi All,

Can any one help me out to understand liferay enchace behavior for "timeToIdleSeconds" secs. I have a "employee" Object and i am using liferay encache to persist in cache as follows.

MultiVMPoolUtil.put("EMPLOYEE_OBJ_CACHE","empName",empObj);

Here
"EMPLOYEE_OBJ_CACHE" is the cache name
"empName" is the employee Name for the corresponding Employee Object(empObj)
"empObj" is the employee Object

Since our Project is running in Cluster environment , i have given entry in "liferay-multi-vm-clustered.xml" as below

<cache
eternal="false"
maxElementsInMemory="2000"
name="EMPLOYEE_OBJ_CACHE"
overflowToDisk="false"
timeToIdleSeconds="600"
>
<cacheEventListenerFactory
class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory"
properties="replicatePuts=true,replicatePutsViaCopy=true,replicateUpdatesViaCopy=true,replicateRemovals=true"
propertySeparator=","
/>
<bootstrapCacheLoaderFactory class="com.liferay.portal.cache.ehcache.LiferayBootstrapCacheLoaderFactory" />
</cache>

As we know i can get employee Object by passing "employee name" as key as follows

Employee emp= (Employee)MultiVMPoolUtil.get("EMPLOYEE_OBJ_CACHE", "XYZ");

Here "XYZ" is employee name

Now Question is
Does the above employee cache will get NULL after 600 secs if it is ideal Only for that Particular Employee (lets say XYZ) ? (or)
Irrespective of the employee whole cache will get NULL after 600 secs if it is ideal ?

Thanks & Regards,
Suman.
thumbnail
Andrew Jardine, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
I believe it is the objects themselves that timeout, not the entire cache. So if you put employee XYZ into the cache but don't access it again for 600 seconds, that object will be invalidated.
thumbnail
Sushil Patidar, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

Expert Mensajes: 467 Fecha de incorporación: 31/10/11 Mensajes recientes
Hi

Agree with Andrew. I t is the maximum number of seconds an element can exist in the cache without being accessed. The element expires at this limit and will no longer be returned from the cache.

Regards
Suman A, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

New Member Mensajes: 9 Fecha de incorporación: 30/07/15 Mensajes recientes
Thanks a lot for the below Confirmation :-) , Since we are giving Cache name entry in liferay-multi-vm-clustered.xml . So i was in the impression that liferay caching mechanism works on all the objects for the specific cache name rather than each individual Object.
thumbnail
Andrew Jardine, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
Nope -- same principle. That just allows you to create your own "bucket" to store objects and configure the "bucket" with different settings than the others. For example, you may create a bucket that stores records that you know are only refreshed every 2 weeks. You could then set a timeToLive so that it expires right before the refresh. This way you know that once you have gone through the effort to retrieve the data -- you can safely store it for a longer period than something else that is more volatile (which you might place is a different "bucket" you define).

Cache analysis and tuning is definitely an important part of performance testing and configuration -- something that is often overlooked unfortunately.

Anyway, glad you got it solved.
thumbnail
Vicente Soriano Martinez, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

New Member Mensajes: 20 Fecha de incorporación: 23/07/14 Mensajes recientes
I'm running some tests about this right now with a custom entity made with SB.
I want to modify the timeToLiveSeconds and timeToIdleSeconds properties from ehcache for that custom entity... is there a way to put that configuration inside the SB code instead of manually modifying an xml from outside?
I find it quite interesting if you're interested in managing the time to maintain your entities in the cache, and keeping all those configurations in the same plugin.

Regards.
thumbnail
Andrew Jardine, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

Liferay Legend Mensajes: 2416 Fecha de incorporación: 22/12/10 Mensajes recientes
If the is, if a, not aware of it. Service builder is designed for entity definitions in terms of their attributes and data types... and if guess you could argue their api/storage. Caching is something else altogether and doesn't necessarily have anything to do with the entities you generate (there is no requirement to have them cached afterall)

It'd certainly be a neat feature but it think for now the only way to do what you are looking for is to put the details for how to deal with the cache objects in the cache configuration itself. Don't forget that the bucket just stores serialized objects. You can technically put any object you want (even if it doesn't make sense) into the bucket you define -- there is not ype checking done.
thumbnail
Vicente Soriano Martinez, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

New Member Mensajes: 20 Fecha de incorporación: 23/07/14 Mensajes recientes
Thanks for your answer, Andrew.

I totally agree with you, it would be a neat feature to include in SB configurations, seeing how you can configure aspects of Hibernate or the DB model itself (as a matter of fact, you can define if the entity uses the cache at all with the cache-enabled attribute). Custom treatment for the entities generated with service builders should have special cache treatment too (in case you want to, obviously).
I need to reread the documentation about Distributed caching and do some more tests. If I find something useful, I'll reply this post.

Regards.
thumbnail
Vicente Soriano Martinez, modificado hace 7 años.

RE: "timeToIdleSeconds" secs Behavior in liferay

New Member Mensajes: 20 Fecha de incorporación: 23/07/14 Mensajes recientes
Hi everyone,

after a few tests, I've built successfully a plugin with custom configurations for my entities, with different timeToIdleSeconds and timeToLiveSeconds.
As I wrote earlier, everything is explained in the Distributed Caching documentation, but I'll write how I did it.

You can implement in your own plugin the configuration you want to have for ehcache. As Andrew said, you can put in the entities you want to save in cache, it doesn't matter if they don't exist. This actually brings us the possibility to have that feature we were talking about, i.e. put the ehcache configuration together with the definition of our entites in a Service Builder. However my use case is quite different than this, and I need to put several configurations for a couple of entites from different SB, and each one has its own set of properties. Therefore, instead of putting all my files inside the SB, I've made a custom plugin whose mission is to configure the cache of all my entities.

This is what I did:
  • Create an empty hook plugin
  • Create a file portlet.properties
    [indent]Add these lines to that file: (see the link I post about the distributed caching to know the purpose of each one)[/indent]
    net.sf.ehcache.configurationResourceName=/custom_cache/hibernate-clustered.xml
    ehcache.single.vm.config.location=/custom_cache/liferay-single-vm.xml
    ehcache.multi.vm.config.location=/custom_cache/liferay-multi-vm-clustered.xml

  • Create a custom folder for my configuration xmls (in this case, named custom_cache, as I included in the previous file)
  • Copy and paste the original 3 files from portal-impl/ehcache: hibernate-clustered.xml, liferay-single-vm.xml, liferay-multi-vm-clustered.xml
  • Write my own configuration for my entites
    [indent]In my case, I included these lines in the liferay-multi-vm-clustered.xml file:[/indent]
    <cache eternal="false" maxelementsinmemory="50000" name="com.liferay.portal.kernel.dao.orm.EntityCache.com.test.visomar.model.impl.CustomEntityImpl" overflowtodisk="false" timetoidleseconds="10" timetoliveseconds="20">
    	<cacheeventlistenerfactory class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory" properties="replicatePuts=false,replicateUpdatesViaCopy=false" propertySeparator="," />
    </cache>
    <cache eternal="false" maxelementsinmemory="50000" name="com.liferay.portal.kernel.dao.orm.FinderCache.com.test.visomar.model.impl.CustomEntityImpl" overflowtodisk="false" timetoidleseconds="10" timetoliveseconds="20">
    	<cacheeventlistenerfactory class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory" properties="replicatePuts=false,replicateUpdatesViaCopy=false" propertySeparator="," />
    </cache>
    <cache eternal="false" maxelementsinmemory="50000" name="com.liferay.portal.kernel.dao.orm.FinderCache.com.test.visomar.model.impl.CustomEntityImpl.List1" overflowtodisk="false" timetoidleseconds="10" timetoliveseconds="20">
    	<cacheeventlistenerfactory class="com.liferay.portal.cache.ehcache.LiferayCacheEventListenerFactory" properties="replicatePuts=false,replicateUpdatesViaCopy=false" propertySeparator="," />
    </cache>
    
  • Deploy the plugin


With this example, I could check that my entities only stayed cached for 10 seconds between accesses, and 20 seconds in total.
To know the exact name of the objects I used JConsole to monitor my server's cache.
Also to note here, I use Maven to build my projects, so both portlet.properties and custom_cache go into the src/main/resources folder. If you need to know where they go in an Ant project, the documentation also tells that.

I hope this will be useful to anyone who wants to manage these kind of settings.

Regads.
-Vicente