Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Liferay cache implementation
Hi,
I would like to know Liferay cache system.
I have to get all liferay users along with social equity points and save them in cache( suppose 70,000 users).
External systems use web service to get x(5000) number of users details,then it should fetch data from cache and return back.
Can anybody suggests me how can i implement caching for the above scenario?
I would like to know Liferay cache system.
I have to get all liferay users along with social equity points and save them in cache( suppose 70,000 users).
External systems use web service to get x(5000) number of users details,then it should fetch data from cache and return back.
Can anybody suggests me how can i implement caching for the above scenario?
Hi
I am not sure but liferay already have cache implementation using Ehcache so for each entity we can use cache mechanism
the following is info from service builder DTD
https://github.com/liferay/liferay-portal/blob/master/definitions/liferay-service-builder_6_2_0.dtd
The cache-enabled value specifies whether or not to cache this queries for this
entity. Set this to false if data in the table will be updated by other
programs. The default value is true
Relevant properties
#
# Set the Hibernate cache region factory. Ehcache is recommended in a
# clustered environment. See the property
# "net.sf.ehcache.configurationResourceName" for detailed configuration.
#
hibernate.cache.region.factory_class=com.liferay.portal.dao.orm.hibernate.region.SingletonLiferayEhcacheRegionFactory
#
# This property is used if Hibernate is configured to use Ehcache's region
# factory.
#
net.sf.ehcache.configurationResourceName=/ehcache/hibernate-clustered.xml
#
# Configure this property if using Ehcache's default replication method for
# Hibernate's region cache.
#
net.sf.ehcache.configurationResourceName.peerProviderProperties=peerDiscovery=automatic,multicastGroupAddress=${multicast.group.address["hibernate"]},multicastGroupPort=${multicast.group.port["hibernate"]},timeToLive=1
#
# Set other Hibernate cache settings.
#
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_minimal_puts=true
hibernate.cache.use_structured_entries=false
#
# Uncomment these properties to disable Hibernate caching.
#
#hibernate.cache.use_query_cache=false
#hibernate.cache.use_second_level_cache=false
##
## Transactional Cache
##
#
# Set this property to true to enable transactional cache. When enabled,
# changes to caches take effect when transaction commits successfully.
# Caches rollback when transactions rollback.
#
transactional.cache.enable=true
##
## Ehcache
##
#
# Set the classpath to the location of the Ehcache config file for internal
# caches. Edit the file specified in the property
# "ehcache.multi-vm.config.location" to enable clustered cache.
#
ehcache.single.vm.config.location=/ehcache/liferay-single-vm.xml
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm-clustered.xml
#
# Uncomment the following in a clustered environment.
#
ehcache.multi.vm.config.location.peerProviderProperties=peerDiscovery=automatic,multicastGroupAddress=${multicast.group.address["multi-vm"]},multicastGroupPort=${multicast.group.port["multi-vm"]},timeToLive=1
#
# Input a class name that extends
# net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory. This class is used
# by Ehcache to determine how caches communicate with each other in a
# clustered environment.
#
ehcache.bootstrap.cache.loader.factory=net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory
#ehcache.bootstrap.cache.loader.factory=com.liferay.portal.cache.ehcache.JGroupsBootstrapCacheLoaderFactory
#
# Input a class name that extends
# net.sf.ehcache.event.CacheEventListenerFactory. This class is used by
# Ehcache to determine how caches communicate with each other in a clustered
# environment.
#
ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.RMICacheReplicatorFactory
#ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory
#
# Input a class name that extends
# net.sf.ehcache.distribution.CacheManagerPeerProviderFactory. This class is
# used by Ehcache to determine how caches communicate with each other in a
# clustered environment.
#
ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
#ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory
#
# Set this to true to enable JMX integration in
# com.liferay.portal.cache.EhcachePortalCacheManager. Set this to false if
# the portal needs to be reloaded under WebSphere.
#
ehcache.portal.cache.manager.jmx.enabled=true
#
# Set this to true to allow Ehcache to use blocking caches. This improves
# performance significantly by locking on keys instead of the entire cache.
# The drawback is that threads can hang if the cache is not used properly.
# Make sure that all queries that return a miss also immediately populate
# the cache, or else other threads that are blocked on a query of that same
# key will continue to hang. Reference Ehcache's BlockingCache for more
# information. The blocking cache is no longer implemented by Ehcache's
# BlockingCache, but by Liferay's BlockingPortalCache for better safety and
# faster performance.
#
ehcache.blocking.cache.allowed=true
#
# Set this to true to enable Ehcache statistics.
#
ehcache.statistics.enabled=false
#
# Value objects are cached at three levels. They first level is "entity",
# the second level is "finder", and the third level is "Hibernate".
#
# The entity level cache stores a value object's primary key to the value
# object itself.
#
# The finder level cache stores the many paths that return a
# value object and the many paths that return a list of value objects. The
# finder level cache only caches primary keys and is further helped by the
# entity level cache that caches the value object to the primary key.
#
# The Hibernate level cache is provided by the
# "hibernate.cache.provider_class" property.
#
#
# Set this to true to enable entity level caching.
#
value.object.entity.cache.enabled=true
#
# Set this to true to configure entity level caching to block. See the
# property "ehcache.blocking.cache.allowed" for more information.
#
value.object.entity.blocking.cache=true
#
# The entity level cache uses a thread local map to store the most
# frequently accessed items to lower the number of queries to the underlying
# cache. Set the maximum map size to 0 to disable the thread level cache.
#
value.object.entity.thread.local.cache.max.size=100
#
# Entity level caching for a specific type of value object can be configured
# by using a property name that includes the value object's class name.
#
value.object.entity.cache.enabled.com.liferay.portal.model.Layout=true
value.object.entity.cache.enabled.com.liferay.portal.model.User=true
#
# Set this to true to enable finder level caching.
#
value.object.finder.cache.enabled=true
#
# Set this to true to configure finder level caching to block. See the
# property "ehcache.blocking.cache.allowed" for more information.
#
value.object.finder.blocking.cache=true
#
# The finder level cache uses a thread local map to store the most
# frequently accessed items to lower the number of queries to the underlying
# cache. Set the maximum map size to 0 to disable the thread level cache.
#
value.object.finder.thread.local.cache.max.size=100
#
# Finder level caching for a specific type of value object can be configured
# by using a property name that includes the value object's class name.
# Mapping tables can also be specified to configure the caching of value
# object relationships.
#
value.object.finder.cache.enabled.com.liferay.portal.model.Layout=true
value.object.finder.cache.enabled.com.liferay.portal.model.User=true
value.object.finder.cache.enabled.Users_Roles=true
Relevant links
https://www.liferay.com/documentation/liferay-portal/6.0/administration/-/ai/distributed-cachi-4
https://www.liferay.com/community/wiki/-/wiki/Main/ehCache+Configuration
http://www.apoorvaprakash.in/2012/03/liferay-cache-key-to-improve.html
http://blogs.xtivia.com/home/-/blogs/caching-observations-in-liferay-6
https://liferayzone.wordpress.com/2012/06/15/liferay-ehcache-configuration-distributed-caching-in-liferay/
https://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Liferay+Caching
Regards,
Meera Prince
I am not sure but liferay already have cache implementation using Ehcache so for each entity we can use cache mechanism
the following is info from service builder DTD
https://github.com/liferay/liferay-portal/blob/master/definitions/liferay-service-builder_6_2_0.dtd
The cache-enabled value specifies whether or not to cache this queries for this
entity. Set this to false if data in the table will be updated by other
programs. The default value is true
Relevant properties
#
# Set the Hibernate cache region factory. Ehcache is recommended in a
# clustered environment. See the property
# "net.sf.ehcache.configurationResourceName" for detailed configuration.
#
hibernate.cache.region.factory_class=com.liferay.portal.dao.orm.hibernate.region.SingletonLiferayEhcacheRegionFactory
#
# This property is used if Hibernate is configured to use Ehcache's region
# factory.
#
net.sf.ehcache.configurationResourceName=/ehcache/hibernate-clustered.xml
#
# Configure this property if using Ehcache's default replication method for
# Hibernate's region cache.
#
net.sf.ehcache.configurationResourceName.peerProviderProperties=peerDiscovery=automatic,multicastGroupAddress=${multicast.group.address["hibernate"]},multicastGroupPort=${multicast.group.port["hibernate"]},timeToLive=1
#
# Set other Hibernate cache settings.
#
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_minimal_puts=true
hibernate.cache.use_structured_entries=false
#
# Uncomment these properties to disable Hibernate caching.
#
#hibernate.cache.use_query_cache=false
#hibernate.cache.use_second_level_cache=false
##
## Transactional Cache
##
#
# Set this property to true to enable transactional cache. When enabled,
# changes to caches take effect when transaction commits successfully.
# Caches rollback when transactions rollback.
#
transactional.cache.enable=true
##
## Ehcache
##
#
# Set the classpath to the location of the Ehcache config file for internal
# caches. Edit the file specified in the property
# "ehcache.multi-vm.config.location" to enable clustered cache.
#
ehcache.single.vm.config.location=/ehcache/liferay-single-vm.xml
ehcache.multi.vm.config.location=/ehcache/liferay-multi-vm-clustered.xml
#
# Uncomment the following in a clustered environment.
#
ehcache.multi.vm.config.location.peerProviderProperties=peerDiscovery=automatic,multicastGroupAddress=${multicast.group.address["multi-vm"]},multicastGroupPort=${multicast.group.port["multi-vm"]},timeToLive=1
#
# Input a class name that extends
# net.sf.ehcache.bootstrap.BootstrapCacheLoaderFactory. This class is used
# by Ehcache to determine how caches communicate with each other in a
# clustered environment.
#
ehcache.bootstrap.cache.loader.factory=net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory
#ehcache.bootstrap.cache.loader.factory=com.liferay.portal.cache.ehcache.JGroupsBootstrapCacheLoaderFactory
#
# Input a class name that extends
# net.sf.ehcache.event.CacheEventListenerFactory. This class is used by
# Ehcache to determine how caches communicate with each other in a clustered
# environment.
#
ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.RMICacheReplicatorFactory
#ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory
#
# Input a class name that extends
# net.sf.ehcache.distribution.CacheManagerPeerProviderFactory. This class is
# used by Ehcache to determine how caches communicate with each other in a
# clustered environment.
#
ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory
#ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory
#
# Set this to true to enable JMX integration in
# com.liferay.portal.cache.EhcachePortalCacheManager. Set this to false if
# the portal needs to be reloaded under WebSphere.
#
ehcache.portal.cache.manager.jmx.enabled=true
#
# Set this to true to allow Ehcache to use blocking caches. This improves
# performance significantly by locking on keys instead of the entire cache.
# The drawback is that threads can hang if the cache is not used properly.
# Make sure that all queries that return a miss also immediately populate
# the cache, or else other threads that are blocked on a query of that same
# key will continue to hang. Reference Ehcache's BlockingCache for more
# information. The blocking cache is no longer implemented by Ehcache's
# BlockingCache, but by Liferay's BlockingPortalCache for better safety and
# faster performance.
#
ehcache.blocking.cache.allowed=true
#
# Set this to true to enable Ehcache statistics.
#
ehcache.statistics.enabled=false
#
# Value objects are cached at three levels. They first level is "entity",
# the second level is "finder", and the third level is "Hibernate".
#
# The entity level cache stores a value object's primary key to the value
# object itself.
#
# The finder level cache stores the many paths that return a
# value object and the many paths that return a list of value objects. The
# finder level cache only caches primary keys and is further helped by the
# entity level cache that caches the value object to the primary key.
#
# The Hibernate level cache is provided by the
# "hibernate.cache.provider_class" property.
#
#
# Set this to true to enable entity level caching.
#
value.object.entity.cache.enabled=true
#
# Set this to true to configure entity level caching to block. See the
# property "ehcache.blocking.cache.allowed" for more information.
#
value.object.entity.blocking.cache=true
#
# The entity level cache uses a thread local map to store the most
# frequently accessed items to lower the number of queries to the underlying
# cache. Set the maximum map size to 0 to disable the thread level cache.
#
value.object.entity.thread.local.cache.max.size=100
#
# Entity level caching for a specific type of value object can be configured
# by using a property name that includes the value object's class name.
#
value.object.entity.cache.enabled.com.liferay.portal.model.Layout=true
value.object.entity.cache.enabled.com.liferay.portal.model.User=true
#
# Set this to true to enable finder level caching.
#
value.object.finder.cache.enabled=true
#
# Set this to true to configure finder level caching to block. See the
# property "ehcache.blocking.cache.allowed" for more information.
#
value.object.finder.blocking.cache=true
#
# The finder level cache uses a thread local map to store the most
# frequently accessed items to lower the number of queries to the underlying
# cache. Set the maximum map size to 0 to disable the thread level cache.
#
value.object.finder.thread.local.cache.max.size=100
#
# Finder level caching for a specific type of value object can be configured
# by using a property name that includes the value object's class name.
# Mapping tables can also be specified to configure the caching of value
# object relationships.
#
value.object.finder.cache.enabled.com.liferay.portal.model.Layout=true
value.object.finder.cache.enabled.com.liferay.portal.model.User=true
value.object.finder.cache.enabled.Users_Roles=true
Relevant links
https://www.liferay.com/documentation/liferay-portal/6.0/administration/-/ai/distributed-cachi-4
https://www.liferay.com/community/wiki/-/wiki/Main/ehCache+Configuration
http://www.apoorvaprakash.in/2012/03/liferay-cache-key-to-improve.html
http://blogs.xtivia.com/home/-/blogs/caching-observations-in-liferay-6
https://liferayzone.wordpress.com/2012/06/15/liferay-ehcache-configuration-distributed-caching-in-liferay/
https://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Liferay+Caching
Regards,
Meera Prince
Community
Company
Feedback