jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Naveen Ayyagari <nav...@ayyagari.com>
Subject Re: New User Help
Date Wed, 23 May 2007 14:09:52 GMT
I was able to get this working, I didnt implement my class as serializable....

I have a new question.....

I am using JCS inside a stateless EJB...
I understand it is implemented as singleton, so my cache should persist accross different
instances of EJB..

Is this true if I configure my own config file using the following from the faq?
	CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
	Properties props = new Properties();
	props.load(/* load properties from some location defined by your app */);
	ccm.configure(props);

I need the cache to persist, but am worried that it gets a NEW "unconfiguredInstance" each
time?

--Naveen

Naveen Ayyagari wrote:
> Hello,
>     I checked if the result was null before attempting to add to the 
> cache, however I am still unable to add my cacheSet object to the cache...
> 
> As a test I attempted to add a static string "test" as my cached object 
> and that works fine.. What could be the problem with adding the cacheSet 
> object that I created?
> 
> --Naveen
> 
> Al Forbes wrote:
>> Hi,
>>
>> You cannot add null to the database - make sure that result != null.
>>
>> Al
>>
>> On 15/05/07, Naveen Ayyagari <naveen@ayyagari.com> 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: jcs-users-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Mime
View raw message