Table of Contents
ObjectCacheFactory is a factory for objects implementing the ObjectCache interface.
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.)
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:
Caches objects by keeping a soft reference to a cached object in order to enable the garbage collector to reclaim storage.
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.
This package uses exception ClassNotPersistenceCapableException from metadata.
This package uses the class Identity for storing objects. It also uses PersistenceBrokerFactory to retrieve the configuration.
This package uses the logging facility.
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:
Create a new class name FoobarObjectCacheImpl which implements ObjectCache.
Implement all methods according to the method documentation for the methods of ObjectCache.
Update the configuration files of OJB so that the application will use your newly written object cache.
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.