Hi Nissim,

> > 
> > Add a method "resetExpiry()" on the CachedObject class, which resets the created
> > time to now.
 

> Who's going to call this method?

In my code I am writing to test the changes, immediately after I get the object from 
the cache, I call this method - although I can see it might be easier to build it into 
the getObject method - perhaps via a UsageAwareCachedObject subclass override of the 
method - (maybe with a better name ;-)  ).



> I want to be able to put
> something in the cache, and have it be refreshed every five minutes, and
> removed when it hasn't been accessed for 60 minutes.

> The problem is that it currently uses the expire time to cause a refresh
> in refreshable cached objects, so there needs to be another time (like
> last access time) for removing objects that haven't been used in a while.

I agree.


> > Add a listener facility to the CachedObject - allowing you to add/remove
> > listeners conforming to the interface CacheListener, which has 1 method
> > "cachedObjectFinalizer(CachedObject obj)".

> Who are the listeners?  Would they ever be an object other than the
> CachedObject's contents?  
> Maybe if the contents would know how to
> finalize themselves, the finalizeContents() method could be added to
> CachedObject, and called before it's removed from the Hashtable.  The
> finalizeContents would check if the contents implements > CacheListener
> and if so, call the contents cleanup method...

> Maybe I don't understand what you need though...

The thing I want to put in the cache at the moment is a Database object - I don't want 
to add a Turbine/cache specific method just to get it to call its close method - so I 
would create an anonymous class that "adapts" the finalise into a close, like this;





    Database db = null;
    GlobalCacheService gs = 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);
    
      CachedObject obj = gs.getObject(CACHE_NAME_FOR_DB);
      db = (Database)obj.getContents();
      obj.resetExpires();
    
    } catch(ObjectExpiredException gone)
    {
        db = org.melati.poem.odmg.ODMGFactory.getNewDatabase();
        db.open("vgdb",Database.OPEN_READ_WRITE);
        CachedObject obj = new CachedObject(db);
        obj.addListener(new CachedObjectListener() {
                public void cachedObjectFinalizer(CachedObject cobj) {
                    Log.note("in cachedObjectFinalizer for "+cobj);
                    try {
                        Database cdb = (Database)cobj.getContents();
                        cdb.close();
                    } catch (ODMGException exc) {
                        Log.error(exc);
                    }
                    
                }
                
            });
        gs.addObject(CACHE_NAME_FOR_DB, obj);
    }

    return db;



Regards,
Chris

PS I've noticed a bug in the clearCache method - it called hashtable remove on the 
cached object - but that method takes a key - not the value - so it always failed - I 
will fix this too.
---
"surely it is madness to accept life as it is and not as it could be"
______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to