Problem while implementing ehCache Framework

S

Sarkar

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);
}
}

/*
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@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.
 
R

RedGrittyBrick

Experts please comment on it...

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top