Reputation: 512
I am using liferay 6.1
version.
I have created custom entities for portlet using service builder. I want to cache that custom entities.
I have set following properties in my portal-ext.properties to enable cache.
ehcache.statistics.enabled=true
value.object.entity.cache.enabled=true
value.object.finder.cache.enabled=true
velocity.engine.resource.manager.cache.enabled=true
layout.template.cache.enabled=true
net.sf.ehcache.configurationResourceName=/custom_cache/hibernate-clustered.xml
log4j.logger.net.sf.ehcache=DEBUG
log4j.logger.net.sf.ehcache.config=DEBUG
log4j.logger.net.sf.ehcache.distribution=DEBUG
log4j.logger.net.sf.ehcache.code=DEBUG
I created ehcache.xml file to override the ehcache-failsafe.xml to configure my custom entities so that it can enable for caching.
my ehcache.xml file is in my classpath [classpath:liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes].
<diskStore path="java.io.tmpdir/ehcache"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
<cache
eternal="false"
maxElementsInMemory="10000"
name="com.pr.test.model.impl.StudentImpl"
overflowToDisk="false"
timeToIdleSeconds="600"
timeToLiveSeconds="300"
statistics="true"
copyOnRead="true"
copyOnWrite="true"
clearOnFlush="true"
transactionalMode="off"
/>
Also create hibernate-clustered.xml file under src path [/docroot/WEB-INF/src] which is same as my ehcache.xml file.
since I am using service builder, cache-enable="true" is enough to cache the entities?
I use Jconsole
to monitor the cache hits, But what the problem is the percentage for cache Misses is more than cache hits. Below is my statistics for caching :
Any help will be appreciated.
Upvotes: 2
Views: 3777
Reputation: 1141
Caching is enabled by default for services built using liferay service builder.
I believe none of the steps mentioned above are required as cache is default enabled.
Below properties are set to true in default portal.properties and applies to all entities, not just for custom entities.
value.object.entity.cache.enabled=true
value.object.finder.cache.enabled=true
You can open *PersistenceImpl.java class for your custom entities to observe the caching code. Debugging this class could give you details on why its not hitting cache.
For example, calling API with cache off argument won't hit cache.
Upvotes: 4