Brian Gebala found an important bug in the code that I sent out for using OSCache in 
OJB.  
A remove call needs to be made in the cache() call, for the OSCache's "flush event."  
Maybe
one of these days I'll learn how to read since the OSCache docs cover this.  Oh well.

>From Brian's Email:

"Without the call to remove() from within cache(), I would not see the cache
on the remote app updated. The object's changed values were written to
the database, but not propagated to the remote OSCache clients."

Below I've included the fixed Java OSCache implementation file.  Please be sure to 
update
if your using OSCache in a clustered environment.

Thanks Brian.  Sorry for the hassle to anyone doing this.


Jason


HERE'S THAT CLASS
--------------------------------------------------------------
import org.apache.ojb.broker.Identity;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.cache.ObjectCache;
import org.apache.ojb.broker.cache.RuntimeCacheException;

import com.opensymphony.oscache.base.CacheEntry;
import com.opensymphony.oscache.general.GeneralCacheAdministrator;

public class ObjectCacheOSCacheImpl implements ObjectCache {

  private GeneralCacheAdministrator admin;
  private static final int NO_REFRESH = CacheEntry.INDEFINITE_EXPIRY;

  public ObjectCacheOSCacheImpl() {
  }

  public ObjectCacheOSCacheImpl(PersistenceBroker broker) {
      admin = new GeneralCacheAdministrator();
  }

  public void cache(Identity oid, Object obj) {
    try {
        //FIX IS HERE!
      this.remove(oid);
      admin.putInCache(oid.toString(), obj);
    }
    catch (Exception e) {
      throw new RuntimeCacheException(e.getMessage());
    }
  }

  public Object lookup(Identity oid) {
    try {
      return admin.getFromCache(oid.toString(), NO_REFRESH);
    }
    catch (Exception e) {
      return null;
    }
  }

  public void remove(Identity oid) {
    try {
      admin.flushEntry(oid.toString());
    }
    catch (Exception e) {
      throw new RuntimeCacheException(e.getMessage());
    }
  }

  public void clear() {
    if (admin != null) {
      try {
        admin.flushAll();
      }
      catch (Exception e) {
        throw new RuntimeCacheException(e);
      }
    }
  }
}



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

Reply via email to