Hi Armin
> Any warnings, error messages on startup of OJB?
Neither message nor warning. Actually, the application is working fine with
this configuration if not in a cluster.

I have activated the debug level of my ObjectCacheOSCacheInternalImpl class
and all the methods are called (internal or not).

> Did you enable debug-logging level for ObjectCacheTwoLevelImpl, will
objects be cached?
Yes I did, objects are properly cached during session. But actually I would
expect to receive a cache update notification each time a "Move obj from
session cache --> application cache" message is displayed, but i do not
receive any notification.

> Do you use a debugger to track method acces in
ObjectCacheOSCacheInternalImpl?
Yes and it seems to work fine, methods are called properly

> Are you sure that the oscache.properties file is correct and in
> classpath? Any duplicate oscache.properties files in classpath?
The oscache.properties is correct as if I replace the
ObjectCacheOSCacheInternalImpl by the previous version
ObjectCacheOSCacheImpl extending ObjectCache, I can see the notifications


Based on all that I have been seeking a little bit deeper in the OSCache
documentation. Actually, OSCache sends notifications (Events) only on flush
events. The putInCache method do not flush the cache, so no event is sent.
The ObjectCacheOSCacheInternalImpl should force OSCache to flush the entry
in order to generate an events.

Based on that, there is a mistake in the sample code provided : you have to
add a call to remove(oid) just before calling putInCache (twice in the
code).

And now it works fine. Hope this could help anyone else.

Jacques Desmazieres


Here is the code of my current implementation, based on your sample with
just some fixes

public class ObjectCacheOSCacheInternalImpl implements ObjectCacheInternal
{
        private static GeneralCacheAdministrator admin = new
GeneralCacheAdministrator();
        private static final int REFRESH_PERIOD =
com.opensymphony.oscache.base.CacheEntry.INDEFINITE_EXPIRY;
        private Logger log =
Logger.getLogger(ObjectCacheOSCacheInternalImpl.class);

        public ObjectCacheOSCacheInternalImpl(PersistenceBroker broker, 
Properties
prop)
        {
        }

        public void cache(Identity oid, Object obj)
        {
                try
                {
                        remove(oid);
                        admin.putInCache(oid.toString(), obj);
                }
                catch (Exception e)
                {
                        admin.cancelUpdate(oid.toString());
                        log.error("             Error while try to cache 
object: " + oid, e);
                }
        }

        public void doInternalCache(Identity oid, Object obj, int type)
        {
                cache(oid, obj);
        }

        public boolean cacheIfNew(Identity oid, Object obj)
        {
                boolean result = false;
                Cache cache = admin.getCache();
                try
                {
                        cache.getFromCache(oid.toString());
                }
                catch (NeedsRefreshException e)
                {
                        cache( oid, obj );
                        if (log.isDebugEnabled()) log.debug("           
retrieved from application
cache");
                }
                return result;
        }

        public Object lookup(Identity oid)
        {
                try
                {
                        return admin.getFromCache(oid.toString(), 
REFRESH_PERIOD);
                }
                catch (NeedsRefreshException e)
                {
                        // not found in cache
                        if (log.isDebugEnabled()) log.debug("Not found in 
cache: " + oid);
                        admin.cancelUpdate(oid.toString());
                        return null;
                }
                catch (Exception e)
                {
                        log.error("Unexpected error when lookup object from 
cache: " + oid, e);
                        admin.cancelUpdate(oid.toString());
                        return null;
                }
        }

        public void remove(Identity oid)
        {
                try
                {
                        admin.flushEntry(oid.toString());
                }
                catch (Exception e)
                {
                        throw new RuntimeCacheException("Unexpected error when 
remove object from
cache: " + oid, e);
                }
        }

        public void clear()
        {
                try
                {
                        if (log.isDebugEnabled()) log.debug("Clear cache");
                        admin.flushAll();
                }
                catch (Exception e)
                {
                        throw new RuntimeCacheException("Unexpected error while 
clear cache", e);
                }
        }
}




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

Reply via email to