org.apache.ojb.broker.cache
Class ObjectCacheLocalDefaultImpl

java.lang.Object
  extended by org.apache.ojb.broker.cache.ObjectCacheLocalDefaultImpl
All Implemented Interfaces:
ObjectCache

public class ObjectCacheLocalDefaultImpl
extends java.lang.Object
implements ObjectCache

Simple, flexible local ObjectCache implementation using a HashMap to cache given objects.

The cache uses soft-references which allows objects (softly) referenced by the cache to be reclaimed by the Java Garbage Collector when they are not longer referenced elsewhere.

NOTE: Handle with care! If multiple PB instances are used (OJB standard behavior) you will run into synchronization problems.

Implementation configuration properties:

Property Key Property Values
timeout Lifetime of the cached objects in seconds. If expired the cached object was not returned on lookup call (and removed from cache).

Version:
$Id: ObjectCacheLocalDefaultImpl.java 365232 2005-12-21 22:36:07Z tomdz $
Author:
Thomas Mahler, Armin Waibel

Constructor Summary
ObjectCacheLocalDefaultImpl(PersistenceBroker broker, java.util.Properties prop)
           
 
Method Summary
 void cache(Identity oid, java.lang.Object obj)
          Makes object persistent to the Objectcache.
 boolean cacheIfNew(Identity oid, java.lang.Object obj)
           
 void clear()
          Clear ObjectCache.
 java.lang.Object lookup(Identity oid)
          Lookup object with Identity oid in objectTable.
 void remove(Identity oid)
          Removes an Object from the cache.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectCacheLocalDefaultImpl

public ObjectCacheLocalDefaultImpl(PersistenceBroker broker,
                                   java.util.Properties prop)
Method Detail

clear

public void clear()
Clear ObjectCache. I.e. remove all entries for classes and objects.

Specified by:
clear in interface ObjectCache

cache

public void cache(Identity oid,
                  java.lang.Object obj)
Makes object persistent to the Objectcache. I'm using soft-references to allow gc reclaim unused objects even if they are still cached.

Specified by:
cache in interface ObjectCache
Parameters:
oid - Identity of the object to cache.
obj - The object to cache.

cacheIfNew

public boolean cacheIfNew(Identity oid,
                          java.lang.Object obj)

lookup

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

Specified by:
lookup in interface ObjectCache
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

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

Specified by:
remove in interface ObjectCache
Parameters:
oid - Identity of the object to be removed.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


(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