| java.lang.Object org.apache.ojb.broker.cache.ObjectCacheDefaultImpl
ObjectCacheDefaultImpl | public class ObjectCacheDefaultImpl implements ObjectCacheInternal,PBStateListener(Code) | | This global ObjectCache stores all Objects loaded by the PersistenceBroker
from a DB using a static
java.util.Map . This means each
ObjectCache instance associated with all
PersistenceBroker instances use the same
Map to cache objects. This could lead in "dirty-reads" (similar to read-uncommitted
mode in DB) when a concurrent thread look up same object modified by another thread.
When the PersistenceBroker tries to get an Object by its
Identity .
It first lookups the cache if the object has been already loaded and cached.
NOTE: By default objects cached via
SoftReference which allows
objects (softly) referenced by the cache to be reclaimed by the Java Garbage Collector when
they are not longer referenced elsewhere, so lifetime of cached object is limited by
- the lifetime of the cache object - see property timeout .
- the garabage collector used memory settings - see property useSoftReferences .
- the maximum capacity of the cache - see property maxEntry .
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). Default timeout
value is 900 seconds. When set to -1 the lifetime of
the cached object depends only on GC and do never get timed out.
|
autoSync |
If set true all cached/looked up objects within a PB-transaction are traced.
If the the PB-transaction was aborted all traced objects will be removed from
cache. Default is false.
NOTE: This does not prevent "dirty-reads" (more info see above).
It's not a smart solution for keeping cache in sync with DB but should do the job
in most cases.
E.g. if you lookup 1000 objects within a transaction and modify one object and then abort the
transaction, 1000 objects will be passed to cache, 1000 objects will be traced and
all 1000 objects will be removed from cache. If you read these objects without tx or
in a former tx and then modify one object in a tx and abort the tx, only one object was
traced/removed.
|
cachingKeyType |
Determines how the key was build for the cached objects:
0 - Identity object was used as key, this was the default setting.
1 - Idenity + jcdAlias name was used as key. Useful when the same object metadata model
(DescriptorRepository instance) are used for different databases (JdbcConnectionDescriptor)
2 - Identity + model (DescriptorRepository) was used as key. Useful when different metadata
model (DescriptorRepository instance) are used for the same database. Keep in mind that there
was no synchronization between cached objects with same Identity but different metadata model.
3 - all together (1+2)
|
useSoftReferences |
If set true this class use
java.lang.ref.SoftReference to cache
objects. Default value is true.
|
author: Thomas Mahler version: $Id: ObjectCacheDefaultImpl.java,v 1.24.2.7 2005/12/21 22:24:15 tomdz Exp $ |
Inner Class :final static class OrderedTuple | |
Inner Class :interface CacheEntry | |
Inner Class :final static class CacheEntrySoft extends SoftReference implements CacheEntry | |
Inner Class :final static class CacheEntryHard implements CacheEntry | |
CACHING_KEY_TYPE_PROP | final public static String CACHING_KEY_TYPE_PROP(Code) | | |
SOFT_REFERENCES_PROP | final public static String SOFT_REFERENCES_PROP(Code) | | |
objectTable | final protected static Map objectTable(Code) | | static Map held all cached objects
|
cache | public void cache(Identity oid, Object obj)(Code) | | Makes object persistent to the Objectcache.
I'm using soft-references to allow gc reclaim unused objects
even if they are still cached.
|
clear | public void clear()(Code) | | Clear ObjectCache. I.e. remove all entries for classes and objects.
|
lookup | public Object lookup(Identity oid)(Code) | | Lookup object with Identity oid in objectTable.
Returns null if no matching id is found
|
remove | public void remove(Identity oid)(Code) | | Removes an Object from the cache.
|
|
|