org.apache.ojb.broker.cache
Interface ObjectCache

All Known Subinterfaces:
ObjectCacheInternal
All Known Implementing Classes:
AbstractMetaCache, MaterializationCache, ObjectCacheDefaultImpl, ObjectCacheEmptyImpl, ObjectCacheJCSImpl, ObjectCacheJCSPerClassImpl, ObjectCacheLocalDefaultImpl, ObjectCachePerBrokerImpl, ObjectCachePerClassImpl, ObjectCacheSoftImpl, ObjectCacheTwoLevelImpl

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. This will be internally handled by OJB, no need to take care of this. - 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 365232 2005-12-21 22:36:07Z tomdz $
Author:
Thomas Mahler, Armin Waibel

Method Summary
 void cache(Identity oid, java.lang.Object obj)
          Used to cache objects by it's Identity.
 void clear()
          Clear the cache.
 java.lang.Object lookup(Identity oid)
          Lookup object with Identity 'oid' in cache.
 void remove(Identity oid)
          Removes an Object from the cache.
 

Method Detail

cache

void cache(Identity oid,
           java.lang.Object obj)
Used to cache objects by it's Identity.

Parameters:
oid - Identity of the object to cache.
obj - The object to cache.

lookup

java.lang.Object lookup(Identity oid)
Lookup object with Identity 'oid' in cache.

Parameters:
oid - Identity of the object to search for.
Returns:
The cached object or null if no matching object for specified Identity is found.

remove

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

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

clear

void clear()
Clear the cache.



(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30