The code does not allow result ==  null.

result is created at the top of the if and is never overwritten anywhere, only 
methods Set inside result are modified.
For some reason, cacheSet objects simply to not enter the cache, and I cant 
figure out why.

I was able to implement a cache like structure using a simple Map<String, 
cacheSet> but would much prefer to use JCS for LRUalgorithms.

Again any help would be appreciated.
Thanks
--Naveen

Al Forbes wrote:
Hi,

You cannot add null to the database - make sure that result != null.

Al

On 15/05/07, Naveen Ayyagari <[EMAIL PROTECTED]> wrote:
I am new to JCS and am having difficulty getting it up and running.
It looks like for some reason I am unable to add objects to the cache....
I have included all of my configuration below and hope that you will be able to
point me to what I am doing wrong.


I want to use a simple LRUMemory Cache. I don't care about auxiliary caches in this case.

I have tried configuring this stuff in so many ways....

My Goal is to cache Set<String> objects... To get around the generics casting errors
I have a small class that wraps the set:

private class cacheSet extends Object{
     public Set<String> set = null;
     public cacheSet(){
         set = new LinkedHashSet<String>();
     }
}

I have simplified the function that uses the cache below......

public Set<String> getSet(String Key){
     cacheSet result = null;
     Connection conn = null;


     //Check the Cache First
     result = (cacheSet)unitCache.get(attributeKey);

if(result == null){ //if it wasnt in the cache then go to DB
         result = new cacheSet();
         conn = ds.getConnection();

         /***************
             DATABASE CODE TO POPULATE SET
         ****************/

         try{ //add object to cache
             unitCache.put(attributeKey, (Object)result);
         }
         catch(Exception e){
             //This is not a fatal error it simply did not get cached.
//log the error so that if it happens alot we can troubleshoot it log.info("Unable to add to unitCache: " + e.getMessage() + " cause: " + e.getCause() );
         }
     }

     return result.set;
}

In the log file, I get the following line from my Exception Handler above

INFO: Unable to add to unitCache: cacheSet cause: null


I have tried everything I can think of to make this work.... Please any guidance would be much appreciated.

I am currently configuring the cache region like this in my constructor:
     try{

ICompositeCacheAttributes cacheAttr = new org.apache.jcs.engine.CompositeCacheAttributes();
         cacheAttr.setMaxObjects(500);
cacheAttr.setMemoryCacheName("org.apache.jcs.engine.memory.lru.LRUMemoryCache");
         cacheAttr.setUseLateral( false );
         cacheAttr.setUseRemote( false );
IElementAttributes elemAttr = new org.apache.jcs.engine.ElementAttributes();
         elemAttr.setIsEternal( true );
         elemAttr.setIsSpool( true );
         elemAttr.setIsLateral( false );
         elemAttr.setIsRemote( false );

         JCS.defineRegion("enumCache", cacheAttr, elemAttr);
         JCS.defineRegion("unitCache", cacheAttr, elemAttr);

         enumCache = JCS.getInstance("enumCache");
         unitCache = JCS.getInstance("unitCache");

     }
     catch(Exception e){
         throw new CommonRepositoryDaoSysException(
                 "Unable to setup Cache.", e);
     }

BUT have also tried configuring the region in ccf file like this:
# DEFAULT CACHE REGION
jcs.default=
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=true
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsLateral=false
jcs.default.elementattributes.IsRemote=false

# Regions preconfigured for caching
#unit Cache
jcs.region.unitCache=
jcs.region.unitCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.unitCache.cacheattributes.MaxObjects=1000
jcs.region.unitCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache jcs.region.unitCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.unitCache.elementattributes.IsEternal=true
jcs.region.unitCache.elementattributes.IsSpool=false
jcs.region.unitCache.elementattributes.IsLateral=false
jcs.region.unitCache.elementattributes.IsRemote=false


Thanks
--Naveen





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



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


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

Reply via email to