I've never tried to use EhCache programmatically to store objects.
I've only done that with OSCache. You might try posting this question
to the ehcache mailing list.

Matt

On 9/1/07, j2ee dodo <[EMAIL PROTECTED]> wrote:
>
>
> Hi guys,
>
> I have been trying to prove ehcache work with a testcase
> in appfuse without luck. Can someone enlighten me a bit?
>
> Basically, I added the config as below and turned on
> logging to DEBUG but cache just doesn't seem to be working.
>
> i.e.
>
> I added
>
>    <prop
> key="hibernate.cache.use_second_level_cache">true</prop>
>    <prop
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
>
> to sessionFactory bean in
> applicationContext-hibernate.xml
> as
>
>  <!-- Hibernate SessionFactory -->
>     <bean id="sessionFactory"
> class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
>         <property name="dataSource" ref="dataSource"/>
>         <property name="mappingResources">
>             <list>
>               ....
>             </list>
>         </property>
>         <property name="hibernateProperties">
>             <props>
>                 <prop key="hibernate.dialect">@HIBERNATE-DIALECT@</prop>
>                 <prop key="hibernate.query.substitutions">true 'Y', false
> 'N'</prop>
>                 <!-- Create/update the database tables automatically when
> the JVM starts up
>                 <prop key="hibernate.hbm2ddl.auto">update</prop> -->
>                 <!-- Turn batching off for better error messages under
> PostgreSQL
>                 <prop key="hibernate.jdbc.batch_size">0</prop> -->
>
>                 <prop
> key="hibernate.cache.use_second_level_cache">true</prop>
>                 <prop
> key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
>
>             </props>
>         </property>
>     </bean>
>
> then add xdoclet to the pojo such that generated mapping file looks
> like
>
> ...
>
>
> <class name="org.i18nfuse.model.ApplicationResource"
> table="app_resource" lazy="true">
>
>
>
>
>
>     <cache  usage="read-write"/>
>
>
>
>     .....
>
>
>
>
>
> <setname="keyValues" lazy="true" inverse="true" cascade="all">
>
>     <cache usage="read-write"/>
>
>     <key column="app_resource_id"></key>
>
>
>
>     <one-to-many class="org.i18nfuse.model.KeyValue"/>
>
>
>
> </set>
>
>
> </class> ...
>
> also added to applicationContext-service.xml the line as below for test
> cases
>
>   <bean id="cacheManager"
> class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
> />
>
> the ehcache.xml is just the default one from appfuse
>
> then write up a simple test case such as
>
> public class
> ApplicationResourcePerformance2Test extends BaseDaoTestCase
> {
>
>     private ApplicationResourceDao dao = null;
>
>     // bean defined in applicationContext-service.xml
>     private CacheManager cacheManager;
>
>     public void
> setApplicationResourceDao(ApplicationResourceDao dao) {
>         this.dao = dao;
>     }
>
>  public void setCacheManager(CacheManager cacheManager) {
>   this.cacheManager = cacheManager;
>  }
>
>   public void testCachePerformance() throws Exception
> {
>
>       for (int i = 0; i < 1000; i++ ) {
>        ApplicationResource appRes = new ApplicationResource(
>          String.valueOf(i), String.valueOf(i), String.valueOf(i));
>       }
>
>       StopWatch watch = new StopWatch();
>       watch.start();
>
>        // retrieve all mock data as above
>        List appResList = dao.getApplicationResources(null);
>       watch.stop();
>
>       logger.info( "loading time before caching: " + watch.getTime() );
>
>        printCacheInfo();
>
>       watch.reset();
>       dao.flush();
>
>       // print cache info
>       printCacheInfo();
>       watch.start();
>       appResList = dao.getApplicationResources(null);
>       watch.stop();
>
>       logger.info( "loading time after caching: " + watch.getTime() );
>
>      }
>
>   private void printCacheInfo() {
>          String names[] = cacheManager.getCacheNames();
>    Cache tempCache;
>    for (int i = 0; i < names.length; i++) {
>     tempCache = cacheManager.getCache(names[i]);
>     logger.info("cache name: " + names[i] + ", size: " +
> tempCache.getSize());
>    }
>   }
>
> }
>
> the log for printCacheInfo() is like
>
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(204) |
> Order SQL updates by primary key: disabled
> [i18nfuse] INFO [main]
> SettingsFactory.createQueryTranslatorFactory(369) | Query
> translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
> [i18nfuse] INFO [main] ASTQueryTranslatorFactory.<init>(24)
> | Using ASTQueryTranslatorFactory
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(212) | Query language
> substitutions: {true='Y', false='N'}
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(217) | JPA-QL strict
> compliance: disabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(222) | Second-level
> cache: enabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(226) | Query cache:
> disabled
> [i18nfuse] INFO [main]
> SettingsFactory.createCacheProvider(356) | Cache provider:
> org.hibernate.cache.EhCacheProvider
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(241) | Optimize cache
> for minimal puts: disabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(250) | Structured
> second-level cache entries: disabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(277) | Statistics:
> disabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(281) | Deleted entity
> synthetic identifier rollback: disabled
> [i18nfuse] INFO [main] SettingsFactory.buildSettings(296) | Default
> entity-mode: pojo
> [i18nfuse] INFO [main] SessionFactoryImpl.<init>(161) | building session
> factory
> [i18nfuse] WARN [main] EhCacheProvider.buildCache(86) | Could not find
> configuration [org.i18nfuse.model.ApplicationResource];
> using defaults.
> [i18nfuse] WARN [main] EhCacheProvider.buildCache(86) | Could not find
> configuration [org.i18nfuse.model.KeyValue]; using defaults.
> [i18nfuse] INFO [main]
> SessionFactoryObjectFactory.addInstance(82) | Not binding
> factory to JNDI, no JNDI name configured
> [i18nfuse] WARN [main]
> CacheManager.detectAndFixDiskStorePathConflict(302) |
> Creating a new instance of CacheManager using the diskStorePath
> "C:\DOCUME~1\samuel\LOCALS~1\Temp\" which is already used
> by an existing CacheManager.
> The source of the configuration was classpath.
> The diskStore path for this CacheManager will be set to
> C:\DOCUME~1\samuel\LOCALS~1\Temp\\ehcache_auto_created_1188645946453.
> To avoid this warning consider using the CacheManager factory methods to
> create a singleton CacheManager or specifying a separate ehcache
> configuration (ehcache.xml) for each CacheManager instance.
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.startNewTransaction(309)
> | Began transaction (1): transaction manager
> [EMAIL PROTECTED];
> default rollback = true
>
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.testCachePerformance2(45)
> | loading time before caching: 609
>
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(62) | #
> of cache regions: 2
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(66) |
> cache name: org.i18nfuse.model.ApplicationResource, size: 0
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(66) |
> cache name: userCache, size:
> 0
>
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(62) | #
> of cache regions: 2
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(66) |
> cache name: org.i18nfuse.model.ApplicationResource, size: 0
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.printCacheInfo(66) |
> cache name: userCache, size:
> 0
>
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.testCachePerformance2(56)
> | loading time after caching: 0
>
> [i18nfuse] INFO [main]
> ApplicationResourcePerformance2Test.endTransaction(275) |
> Rolled back transaction after test execution
> [i18nfuse] INFO [Thread-2] SessionFactoryImpl.close(767) |
> closing
>
>
> as you can see above, although loading time seems to have greatly reduced
> in loading all ApplicationResource pojo with
> dao.getApplicationResources(null);
> , the log in printCacheInfo() indicates the cache never stored anything!!!
>
>
> What am I doing wrong? Help.
>
>
> Thanks
>
> Sam


-- 
http://raibledesigns.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to