Package documentation

Frido Budde


Table of Contents

Intent
Patterns used
Diagramms
Detailed Description
Dependencies on other packages
Hints for extending and maintaining this package
Adding a new type of cache
ToDo

Intent

This package provides classes for caching of objects materialized from a datastore.

Patterns used

Factory

ObjectCacheFactory is a factory for objects implementing the ObjectCache interface.

Proxy

MetaObjectCacheImpl is a kind of proxy for the real object caches. (Although it is not a proxy for a single object but for all caches.)

Diagramms

Figure 1. Classes in package cache

Detailed Description

Applications use the ObjectCacheFactory to create new ObjectCaches. These caches supply methods for storing and retrieving objects. Objects can be looked up by their identity which is represented by the class Identiy. Each implementation of ObjectCache represents a different caching strategy. Currently the following caching strategies are supported:

ObjectCacheDefaultImpl

Caches objects by keeping a soft reference to a cached object in order to enable the garbage collector to reclaim storage.

PermanentObjectCacheImpl

This cache keeps strong references to the cached objects. Therefore the garbage collector is not able to reclaim storage. This cache should be used for objects which don't change during the lifetime of the application and are referenced often.

Dependencies on other packages

ojb.broker.metadata

This package uses exception ClassNotPersistenceCapableException from metadata.

ojb.broker

This package uses the class Identity for storing objects. It also uses PersistenceBrokerFactory to retrieve the configuration.

ojb.broker.util

This package uses the logging facility.

Hints for extending and maintaining this package

Adding a new type of cache

Sometimes it is useful to change the caching strategy for all or for a part of the cachable ojbects. In order to do this you have to write a new kind of cache. Let's assume that the name of the caching strategy is Foobar. Then you've got to proceed as follows:

  1. Create a new class name FoobarObjectCacheImpl which implements ObjectCache.

  2. Implement all methods according to the method documentation for the methods of ObjectCache.

  3. Update the configuration files of OJB so that the application will use your newly written object cache.

ToDo

  1. Is it possible to remove the dependency of this package on ojb.broker and ojb.broker.metadata? A cache might me useful outside of OJB. The dependency comes from using Identy and PersistenceBrokerFactory. Is Identy really necessary? We might place the burden of creating a Identy on the class which wants to cache objects (simply by removing the method cache(Object)). Removing the dependency on Identy removes the dependency on ClassNotPersistenceCapableException as well since this exception is thrown in the constructor of Identy.

    The ObjectCacheFactory might get the configuration data from a static method of BaseConfiguration or some other class. This would remove the depency on ojb.broker entirely and making the object cache reusable.