Announcement Announcement Module
Collapse
No announcement yet.
EhCache not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EhCache not working

    Hi,

    I want to have my cache refreshed each 24 hours; I have Ehcache (with a hibernate DAO) configured the following way:

    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="mappingResources">
    <list>
    <value>resources/hibernate/Agentes.hbm.xml</value>
    <value>resources/hibernate/CanalesAgentes.hbm.xml</value>
    <value>resources/hibernate/Pasos.hbm.xml</value>
    <value>resources/hibernate/PasosFormatosVersiones.hbm.xml</value>
    <value>resources/hibernate/Autorizaciones.hbm.xml</value>
    <value>resources/hibernate/MsgGestor.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
    <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.cache.provider_configuration_file_r esource_path">resources/Ehcache.xml</prop>
    </props>
    </property>
    </bean>




    And this is the Ehcahce file (resources/Ehcache.xml), with a cache to be refreshed each 24 hrs.


    <ehcache>
    <!-- Required elements -->
    <diskStore path="/ehchache/cache/"/>
    <defaultCache
    maxElementsInMemory="10000"
    eternal="false"
    timeToIdleSeconds="86400"
    timeToLiveSeconds="86400"
    overflowToDisk="true"/>
    </ehcache>



    The cache files were created at the very first time the application begun, but after that the cache is not being refreshed. As an example of aour DAO, see the foloowing snippets:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping>
    <class name="com.xyz.daoinc.data.hibernate.Agentes" table="AGENTES">
    <cache usage="read-write"/>
    <id name="codagente" column="CODAGENTE">
    <generator class="increment" />
    </id>
    <property name="codagente" column="CODAGENTE" not-null="true" insert="false" update="false" />
    <property name="descripcion" column="DESCRIPCION" />
    <property name="email" column="EMAIL" />
    <property name="indicadorinterno" column="INDICADORINTERNO" />
    <property name="usocanalpreferente" column="USOCANALPREFERENTE" />
    <property name="canalpreferente" column="CANALPREFERENTE" />
    <property name="codigoexplotacion" column="CODIGOEXPLOTACION" />
    </class>
    </hibernate-mapping>



    public class AgentesDaoImpl implements AgentesDao{

    private HibernateTemplate hibernateTemplate;

    public void setSessionFactory(SessionFactory sessionFactory) {
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    public Agentes findWhereCodagenteEquals(final String codagente) throws AgentesDaoException {

    Collection collection = (Collection) this.hibernateTemplate.execute(
    new HibernateCallback() {
    public Object doInHibernate(Session session){
    Query query = session.createQuery("from Agentes where codagente=?");
    query.setString(0, codagente);
    query.setCacheable(true);
    return query.list();
    }
    });
    Agentes ret[] = convertToDTO( (List) collection );
    return ret.length==0 ? null : ret[0];

    }
    }



    We are getting the following messages:


    2007-07-16 11:02:31,808-862796585 DEBUG [DefaultMessageListenerContainer-1] opened session at time
    stamp: 4852040301228032 SessionImpl.<init> (lu00EDnea:220 )
    2007-07-16 11:02:32,189-862796966 DEBUG [DefaultMessageListenerContainer-1] checking cached query
    results in region: org.hibernate.cache.StandardQueryCache StandardQueryCache.java (lu00EDnea:? )

    2007-07-16 11:02:32,280-862797057 DEBUG [DefaultMessageListenerContainer-1] key: sql: select agent
    es0_.CODAGENTE as CODAGENTE0_, agentes0_.DESCRIPCION as DESCRIPC2_0_, agentes0_.EMAIL as EMAIL0_,
    agentes0_.INDICADORINTERNO as INDICADO4_0_, agentes0_.USOCANALPREFERENTE as USOCANAL5_0_, agentes0
    _.CANALPREFERENTE as CANALPRE6_0_, agentes0_.CODIGOEXPLOTACION as CODIGOEX7_0_ from AGENTES agente
    s0_ where agentes0_.CODAGENTE=?; parameters: 0021, ; named parameters: {} EhCache.java (lu00EDnea:
    ? )
    2007-07-16 11:02:32,334-862797111 DEBUG [DefaultMessageListenerContainer-1] org.hibernate.cache.St
    andardQueryCache Memory cache hit, but element expired Cache.java (lu00EDnea:? )
    2007-07-16 11:02:32,412-862797189 DEBUG [DefaultMessageListenerContainer-1] Element for sql: selec
    t agentes0_.CODAGENTE as CODAGENTE0_, agentes0_.DESCRIPCION as DESCRIPC2_0_, agentes0_.EMAIL as EM
    AIL0_, agentes0_.INDICADORINTERNO as INDICADO4_0_, agentes0_.USOCANALPREFERENTE as USOCANAL5_0_, a
    gentes0_.CANALPREFERENTE as CANALPRE6_0_, agentes0_.CODIGOEXPLOTACION as CODIGOEX7_0_ from AGENTES
    agentes0_ where agentes0_.CODAGENTE=?; parameters: 0021, ; named parameters: {} is null EhCache.j
    ava (lu00EDnea:? )
    2007-07-16 11:02:32,455-862797232 DEBUG [DefaultMessageListenerContainer-1] query results were not
    found in cache StandardQueryCache.java (lu00EDnea:? )
    2007-07-16 11:02:32,484-862797261 DEBUG [DefaultMessageListenerContainer-1] about to open Prepared
    Statement (open PreparedStatements: 0, globally: 0) AbstractBatcher.logOpenPreparedStatement (lu00
    EDnea:358 )



    Thanks in advanced!!!
    Last edited by gcorro; Jul 16th, 2007, 10:10 AM.

  • #2
    And one more thing, Spring seems to resolve properly the paths of the EhCache file, but shows some strage messages at start-up.

    thanks again!

    2007-07-06 11:22:53,319-18096 DEBUG [main ] Creating EhCacheProvider from a specified resource: validadorprincipal/resources/Ehcache.xml Resolved to URL: file:/program/resources/Ehcache.xml EhCacheProvider.loadResource (lu00EDnea:146 )
    2007-07-06 11:22:53,329-18106 DEBUG [main ] Configuring ehcache from URL: file:/program/resources/Ehcache.xml ConfigurationFactory.parseConfiguration (lu00EDnea:87 )
    2007-07-06 11:22:53,330-18107 DEBUG [main ] Configuring ehcache from InputStream ConfigurationFactory.parseConfiguration (lu00EDnea:139 )
    2007-07-06 11:22:53,352-18129 DEBUG [main ] Disk Store Path: /ehchache/cache/ DiskStoreConfiguration.setPath (lu00EDnea:65 )
    2007-07-06 11:22:53,360-18137 DEBUG [main ] No CacheManagerEventListenerFactory class specified. Skipping... ConfigurationHelper.createCacheManagerEventListene r (lu00EDnea:208 )
    2007-07-06 11:22:53,361-18138 DEBUG [main ] No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener. ConfigurationHelper.createCachePeerListener (lu00EDnea:183 )
    2007-07-06 11:22:53,362-18139 DEBUG [main ] No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider. ConfigurationHelper.createCachePeerProvider (lu00EDnea:159 )
    2007-07-06 11:22:53,377-18154 DEBUG [main ] No BootstrapCacheLoaderFactory class specified. Skipping... ConfigurationHelper.createBootstrapCacheLoader (lu00EDnea:135 )
    2007-07-06 11:22:53,407-18184 DEBUG [main ] instantiating cache region: com.xyz.daoinc.data.hibernate.CanalesAgentes usage strategy: read-write CacheFactory.createCache (lu00EDnea:39 )
    2007-07-06 11:22:53,409-18186 WARN [main ] Could not find configuration [com.xyz.daoinc.data.hibernate.CanalesAgentes]; using defaults. EhCacheProvider.buildCache (lu00EDnea:86 )
    2007-07-06 11:22:53,438-18215 DEBUG [main ] Deleting data file com.xyz.daoinc.data.hibernate.CanalesAgentes.data DiskStore.initialiseFiles (lu00EDnea:182 )
    2007-07-06 11:22:53,460-18237 DEBUG [main ] Initialized net.sf.ehcache.store.LruMemoryStore for com.xyz.daoinc.data.hibernate.CanalesAgentes MemoryStore.<init> (lu00EDnea:73 )
    2007-07-06 11:22:53,462-18239 DEBUG [main ] com.xyz.daoinc.data.hibernate.CanalesAgentes Cache: Using SpoolingLinkedHashMap implementation LruMemoryStore.loadMapInstance (lu00EDnea:71 )
    2007-07-06 11:22:53,463-18240 DEBUG [main ] Initialised cache: com.xyz.daoinc.data.hibernate.CanalesAgentes Cache.initialise (lu00EDnea:429 )
    2007-07-06 11:22:53,465-18242 DEBUG [main ] started EHCache region: com.xyz.daoinc.data.hibernate.CanalesAgentes EhCacheProvider.buildCache (lu00EDnea:89 )
    2007-07-06 11:22:54,623-19400 DEBUG [main ] Static SQL for entity: com.xyz.daoinc.data.hibernate.CanalesAgentes AbstractEntityPersister.logStaticSQL (lu00EDnea:2688)
    2007-07-06 11:22:54,624-19401 DEBUG [main ] Version select: select IDCANALAGENTE from CANALESAGENTES where IDCANALAGENTE =? AbstractEntityPersister.logStaticSQL (lu00EDnea:2693)

    Comment

    Working...
    X