I still have a problem in getting the cached object. Here are the codes.
private Physician loadPhysician(RunData data, Object id) throws
Exception
{
GlobalCacheService gs = null;
CachedObject obj = null;
try
{
/*
* Look for the item in the cache.
* If it doesn't exist or the item is stale,
* the cache will throw an exception.
*/
gs = (GlobalCacheService) TurbineServices.getInstance()
.getService(GlobalCacheService.SERVICE_NAME);
obj = gs.getObject("cached_physician");
}
catch(ObjectExpiredException gone)
{
Criteria crit = new Criteria();
crit.add(PhysicianPeer.OBJECT_ID, id);
List v = PhysicianPeer.doSelect(crit);
Physician object = null;
if (v.size() > 0)
{
object = (Physician) v.get(0);
}
else
{
object = new Physician(this.getClient(data));
}
/*
* Add the physician to the cache.
*/
gs.addObject("cached_physician",
new CachedObject(object,5000));
return object;
}
return ??????
}
How can the cached physician object be returned?
Since I can't just cast CachedObject into Physician like
return (Physician)obj
Appreciate your help.
Jill
-----Original Message-----
From: Thomas Vandahl [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 10, 2007 12:36 PM
To: Turbine Users List
Subject: Re: caching object
jill han wrote:
> In the usage section,
> data.setMessage( data.getScreen() + " Got " +
> obj.getContents().toString() + " from global cache!" );
>
> what kind of object is data? Is it RunData object?
Yes. However this is just an example that stands for a real usage of the
cached object. Whatever you put into the cache will be returned by
obj.getContents(). The example shows the pattern:
- try to get the object from the cache
- if it's not there, an ObjectExpiredException is thrown
- in the catch()-branch create the object, wrap it into a CachedObject
and put it into the cache
- then return the value of the cached object.
Hope it helps.
Bye, Thomas.
---------------------------------------------------------------------
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]