title: Liferay custom entity caching
body: <p>I am using <code>liferay 6.1</code> version.</p>
  
  <p>I have created custom entities for portlet using service builder. I want to cache that custom entities.</p>
  
  <p>I have set following properties in my <strong>portal-ext.properties</strong> to enable cache.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I created <strong>ehcache.xml</strong> file to override the <strong>ehcache-failsafe.xml</strong> to configure my custom entities so that it can enable for caching.</p>
  
  <p>my <strong>ehcache.xml</strong> file is in my classpath <strong>[classpath:liferay-portal-6.1.1-ce-ga2/tomcat-7.0.27/webapps/ROOT/WEB-INF/classes]</strong>.</p>
  
  <p></p>
  
  <pre><code>&lt;diskStore path="java.io.tmpdir/ehcache"/&gt;
  
  &lt;defaultCache
          maxElementsInMemory="10000"
          eternal="false"
          timeToIdleSeconds="120"
          timeToLiveSeconds="120"
          overflowToDisk="true"
          maxElementsOnDisk="10000000"
          diskPersistent="false"
          diskExpiryThreadIntervalSeconds="120"
          memoryStoreEvictionPolicy="LRU"
          /&gt;
  
  &lt;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"
      /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Also create <strong>hibernate-clustered.xml</strong> file under src path <strong>[/docroot/WEB-INF/src]</strong> which is same as my <strong>ehcache.xml</strong> file.</p>
  
  <p>since I am using service builder, cache-enable="true" is enough to cache the entities?</p>
  
  <p>I use <code>Jconsole</code> 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 :</p>
  
  <p><img src="https://i.stack.imgur.com/H6dMf.png" alt="cashing statistics![][1]"></p>
  
  <p>Any help will be appreciated.</p>