Thank you.
The issue is that there are multiple applications using the EJB. And the EJB is
stateless,
so I would like all instances of the EJB to use the same Cache. I am fairly
certain that
the default JCS instance is singleton so this would solve my problem, but i
would like to
NOT use the default cache.ccf file because the application is running on a
server with
other application that may update/change the ccf file and mess up my EJB...
--Naveen
Dennis Jacobs wrote:
Naveen,
You should use the code sample you provided only once during some kind of
application initialization. After the instance is configured you should
only be issuing get()s and put()s through the static 'JCS' class interface
ex:
Object key = "key";
Object value = "value";
JCS cache = JCS.getInstance("myRegion");
cache.put(key, value);
Object myValue = cache.get(key);
I'm not sure what subsequent calls would do, but I would avoid calling
ccm.configure(...) multiple times in your application.
Hope that helps,
Dennis
-----Original Message-----
From: Naveen Ayyagari [mailto:[EMAIL PROTECTED]
Sent: Wednesday, May 23, 2007 7:10 AM
To: JCS Users List
Subject: [heur][faked-from] Re: New User Help
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 <[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.LRUMemoryCach
e");
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.CompositeCacheAtt
ributes
jcs.region.unitCache.cacheattributes.MaxObjects=1000
jcs.region.unitCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.m
emory.lru.LRUMemoryCache
jcs.region.unitCache.elementattributes=org.apache.jcs.engine.ElementAttribut
es
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]
---------------------------------------------------------------------
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]