Note that there are some explanatory texts on larger screens.

plurals
  1. POEhCache: Simple Program not working
    text
    copied!<p>I'm new to EhCache, and on the way to implement as a distributed cache service. I was trying out simple programs, but not able to work out the error. I'm able to store data to cache, but not able to retrieve it. </p> <p>These are two simple programs i wrote for testing.</p> <pre><code> package com.db.tests; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; public class TestCachePut { public TestCachePut() { // TODO Auto-generated constructor stub } /** * @param args */ public static void main(String[] args) { CacheManager cache= CacheManager.create("E:/ehcache-2.6.2/ehcache.xml"); Cache caches = cache.getCache("cache1"); Element element= new Element("testKey", "inserted to cache"); caches.put(element); System.out.println("Put in to cache"); } } </code></pre> <p>Program 2:</p> <pre><code> package com.db.tests; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; public class TestCacheGet { public TestCacheGet() { // TODO Auto-generated constructor stub } /** * @param args */ public static void main(String[] args) { CacheManager caches = CacheManager.getInstance(); Element val = caches.getCache("cache1").get("testKey"); System.out.println(" cache content: "+val.getValue()); } } </code></pre> <p>I have the ehcache.xml configured like <code>&lt;cache name="cache1" maxEntriesLocalHeap="10000" maxEntriesLocalDisk="1000" eternal="false" diskSpoolBufferSizeMB="20" timeToIdleSeconds="3000" timeToLiveSeconds="6000" memoryStoreEvictionPolicy="LFU" transactionalMode="off"&gt; &lt;persistence strategy="localTempSwap"/&gt; &lt;/cache&gt;</code></p> <p>Teracotta server is started, and showing its running. When I run Program 1, it runs without any error. After which i ran second one , i got error as NPE,</p> <pre><code> 24 Dec, 2012 12:05:42 PM net.sf.ehcache.config.ConfigurationFactory parseConfiguration WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/E:/ehcache-2.6.2/lib/ehcache-core-2.6.2.jar!/ehcache-failsafe.xml Exception in thread "main" java.lang.NullPointerException at com.db.tests.TestCacheGet.main(TestCacheGet.java:22) </code></pre> <p>if i do specify configuration xml in both cases , its generating again NPE with a warning : </p> <pre><code>4 Dec, 2012 12:22:34 PM net.sf.ehcache.DiskStorePathManager resolveAndLockIfNeeded WARNING: diskStorePath 'E:\Users\SKRISH~1\AppData\Local\Temp' is already used by an existing CacheManager either in the same VM or in a different process. The diskStore path for this CacheManager will be set to E:\Users\SKRISH~1\AppData\Local\Temp\ehcache_auto_created1315701513913502723diskstore. 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. </code></pre> <p>What i'm doing wrong? Some input please.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload