You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Dave Hodson <da...@messagecast.net> on 2004/07/16 00:24:09 UTC

MetaObjectCachePerClassImpl/ObjectCachePerClass/1.0

We're in the process of migrating from RC4 to 1.0

One issue we've run into has to do with caching on a per class basis.

In RC4, we use the MetaObjectCachePerClassImpl class to handle this,
setting a particular class' cache to NULL when we wanted no caching for
that class.

 

In 1.0 we're looking at the ObjectCachePerClass class, as
MetaObjectCachePerClassImpl is no longer available. The cases where we
want to set the caching for a particular class to NULL (i.e. don't
cache) no longer work properly. Instead of returning NULL, they return
the ObjectCacheDefaultImpl class.

 

After a bit of research, I've tracked it down to the method

 

  getCachePerClass(Class objectClass, int methodCall)

 

in ObjectCachePerClass.  

 

Specifically the issue is that a NULL value causes this method to
instantiate a new cache for the class with this line:

 

cache = new ObjectCacheDefaultImpl(null, null);

 

The difference is that MetaObjectCachePerClassImpl would allow for this
(NULL) with this code:

 

        ObjectCache cache = (ObjectCache)
cachesByClass.get(objectClass.getName());

        if (cache == null)

        {

            if (cachesByClass.containsKey(objectClass.getName()))

            {

                //there is a null-cache present => do not cache this
class

            }

            else if (!objectClass.equals(Object.class))

            {

                //check for superclasses cache

                cache = getCachePerClass(objectClass.getSuperclass());

            }

        }

        return cache;

    }

 

It seems like ObjectCacheDefaultImpl needs something similar, like this:

 

    private ObjectCache getCachePerClass(Class objectClass, int
methodCall)

    {

        ObjectCache cache = (ObjectCache)
cachesByClass.get(objectClass.getName());

        if (cache == null && AbstractMetaCache.METHOD_CACHE ==
methodCall)

        {

                        //check to see if this is in the hash

 
if(!cachesByClass.containsKey(objectClass.getName())) {  //<--new code

                                    cache = new
ObjectCacheDefaultImpl(null, null);

                                    setClassCache(objectClass.getName(),
cache);

                        }

        }

        return cache;

    }

 

Thoughts? This works, but I'm wondering if I am missing something

 

Regards

 

Dave