org.apache.ojb.broker.cache
Interface ObjectCache

All Known Implementing Classes:
AbstractMetaCache, ConcreteEditingContext, InternalCache, ObjectCacheDefaultImpl, ObjectCacheEmptyImpl, ObjectCacheJCSImpl, ObjectCacheLocalDefaultImpl, ObjectCachePerBrokerImpl, ObjectCacheSoftImpl, ObjectCacheUnlimitedImpl, TwoLevelCache

public interface ObjectCache

The ObjectCache stores all Objects loaded by the PersistenceBroker from a DB. When the PersistenceBroker tries to get an Object by its Primary key values it first lookups the cache if the object has been already loaded and cached.

Using an ObjectCache has several advantages: - it increases performance as it reduces DB lookups. - it allows to perform circular lookups (as by crossreferenced objects) that would result in non-terminating loops without such a cache. - it maintains the uniqueness of objects as any Db row will be mapped to exactly one object.

This interface allows to have userdefined Cache implementations. The ObjectCacheFactory is responsible for generating cache instances. by default it uses the OJB ObjectCacheDefaultImpl.

Note: Each PersistenceBroker was associated with its own ObjectCache instance at creation time.
ObjectCacheFactory is responsible for creating ObjectCache instances. To make the ObjectCache implementation work, a constructor with PersistenceBroker and Properties as arguments or only PersistenceBroker argument is needed.

Version:
$Id: ObjectCache.java,v 1.7 2003/09/17 23:00:15 arminw Exp $
Author:
Thomas Mahler, Armin Waibel

Method Summary
 void cache(Identity oid, java.lang.Object obj)
          makes object obj persistent to the Objectcache under the key oid.
 void clear()
          clear the ObjectCache.
 java.lang.Object lookup(Identity oid)
          Lookup object with Identity oid in objectTable.
 void remove(Identity oid)
          removes an Object from the cache.
 

Method Detail

cache

public void cache(Identity oid,
                  java.lang.Object obj)
makes object obj persistent to the Objectcache under the key oid.


lookup

public java.lang.Object lookup(Identity oid)
Lookup object with Identity oid in objectTable. returns null if no matching id is found


remove

public void remove(Identity oid)
removes an Object from the cache.

Parameters:
oid - Identity of the object to be removed.

clear

public void clear()
clear the ObjectCache.



Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14