Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Cache is not updated while inserting

2010-11-22
2013-05-14
  • Paul Sudhakar
    Paul Sudhakar
    2010-11-22

    Hi,

    I’m newbie to Ehcache just I started using Ehcache in my Spring-hibernate application. So far I found it very useful but I have one query. Cache is updated while reading and updating but while inserting the data is not being cached. Is there any way to cache while inserting as well apart from do it programmatically.

    I’m configuring Ehcache with my hibernate application as below.

    Hibernate Configuration File :
    <hibernate-mapping default-lazy="false" package="com.poc.dal.domain">
    <class dynamic-insert="false" dynamic-update="false" name="Platform" table="platform">
    <meta attribute="implement-equals">true</meta>
    <cache region="com.poc.dal.domain.Platform" usage="read-write"/>
    <id name="id" type="integer" unsaved-value="0">
    <generator class="increment"/>
    </id>
    <property name="name"/>
    <property column="description" name="description" type="text"/>
    </class>
    </hibernate-mapping>

    Ehcache :

    <ehcache name="DALReadCache"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd">
    <defaultCache
    maxElementsInMemory="300"
    eternal="false"
    timeToIdleSeconds="120"
    timeToLiveSeconds="120">
    </defaultCache>

    <cache name="com.poc.dal.domain.Platform"
    maxElementsInMemory="1000"
    eternal="false"
    timeToIdleSeconds="5200"
    timeToLiveSeconds="5200">
    </cache>
    </ehcache>

    Code :

    this.getHibernateTemplate().saveOrUpdate(platform);