From: Sarkar on
Hi All,

we are getting empty cache name while requesting cache from
cacheManager object to return all cache which are register with it.
/*
Call.java
From main method of call we are initializing the cacheManager.
*/
public class Call {
public static void main(String s[]){
CacheProvider cp = initCache();
System.out.println(cp.getCache("TripDAO"));
}
public static CacheProvider initCache(){
CacheProvider cp = new CacheProvider();
cp.init();
return cp;
}
}

/*
CacheProvider.java
In this class we are creating cacheManager and also adding cache to
created cacheManager
*/
public class CacheProvider {
private CacheManager m_cacheManager = null;

public void init() {
m_cacheManager = new CacheManager();
addCache();
}

private void addCache() {
Ehcache c = new Cache("",
1000,
MemoryStoreEvictionPolicy.LRU,
false, // Overflow to disk
null, // Diskstore path
false, // Eternal
0, // Time to live
0, // Time to idle
false, // Disk persistance
0, // Disk expiry ...
null); // Event listener

CachePopulationManager factory = new
CachePopulationManager("ServiceCatalog","TripDAO");

System.out.println("CachePopulationManager: "+factory);


SelfPopulatingCache spc = new SelfPopulatingCache(c,factory);

System.out.println("SelfPopulatingCache:
"+spc.getCacheManager());

m_cacheManager.addCache(spc);

System.out.println("m_cacheManager.getEhcache(\"TripDAO\"):
"+m_cacheManager.getCacheNames());

String cName[] = m_cacheManager.getCacheNames();

for(int i=0;i<cName.length;i++)
System.out.println("cacheName: "+cName[i]);
}
}

/*
CachePopulationManager.java
*/
public class CachePopulationManager implements CacheEntryFactory,
BootstrapCacheLoader {

* @param entryFactory
* String representing the fully qualified name of the
DAO that
* provides the logic of retreival of a single element
of a certain
* cache
*/
public CachePopulationManager(String cacheName, String
entryFactory) {
m_cacheName = cacheName;
m_entryFactory = entryFactory;
}

/**
* Implementation of a method of the CacheEntryFactory interface,
This method is called
* to create an element according to a given key
*
* @param key The key of the element needs to be created
*/
public Object createEntry(Object key) throws Exception {
Object entry = null;

if (m_entryFactory == null || m_entryFactory.length() == 0) {
throw new Exception("");
}

try {
// call to DAO object to retrun value for requested key
and it'll stored by echCache api
} finally {
}
return entry;
}
}


/// Output of all sysout
CachePopulationManager: dvdrental.cache.CachePopulationManager(a)913750
SelfPopulatingCache: null "we are expecting it should not retrun null"
m_cacheManager.getEhcache("TripDAO"): [Ljava.lang.String;@1bac748
cacheName: //"here we are expecting it should return name of cache
i.e. TripDAP"
null //"we are expecting retrun object of cache"

We are new to cache api. Plesae suggest us...

Thanks & regards, Amit J.


From: Amit Jain on
Experts please comment on it...

Thanks & regards, Amit J.
From: RedGrittyBrick on
On 19/04/2010 11:19, Amit Jain wrote:
> Experts please comment on it...

"Ehcache is actively developed, maintained and supported as a
professional open source project by Terracotta, Inc."


--
RGB
From: Paul Cager on
On Apr 22, 11:19 am, Sarkar <virtexa...(a)gmail.com> wrote:
> Any idea/suggestion how can i correct my program...
>
> thanks & regards, Amit J.

You might have more luck asking on an Ehcache-specific mailing list
(http://ehcache.org/mail-lists.html) or forum (http://
forums.terracotta.org/forums/forums/show/16.page).
From: Sarkar on
Any idea/suggestion how can i correct my program...

thanks & regards, Amit J.