<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/css" href="xhtml.css" ?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"docbook/docbookx.dtd">
<article>
  <title>Package documentation</title>
  <articleinfo>
    <date>13.01.2002</date>
    <author>
      <surname>Budde</surname>
      <firstname>Frido</firstname>
    </author>
  </articleinfo>
  <sect1>
    <title>Intent</title>
    <simpara>This package provides classes for caching of objects materialized from a
    datastore.</simpara>
  </sect1>
  <sect1>
    <title>Patterns used</title>
    <variablelist>
      <varlistentry>
        <term>Factory</term>
        <listitem>
          <para><classname>ObjectCacheFactory</classname> is a factory for objects
          implementing the <classname>ObjectCache</classname> interface.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>Proxy</term>
        <listitem>
          <para>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.)</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </sect1>
  <sect1>
    <title>Diagramms</title>
    <figure>
      <title>Classes in package cache</title>
      <graphic fileref="cache.gif" />
    </figure>
  </sect1>
  <sect1>
    <title>Detailed Description</title>
    <para>Applications use the <classname>ObjectCacheFactory</classname> to create new
    <classname>ObjectCache</classname>s. These caches supply methods for storing and
    retrieving objects. Objects can be looked up by their identity which is represented by
    the class <classname>Identiy</classname>. Each implementation of
    <classname>ObjectCache</classname> represents a different caching strategy. Currently
    the following caching strategies are supported:</para>
    <variablelist>
      <varlistentry>
        <term><classname>ObjectCacheDefaultImpl</classname></term>
        <listitem>
          <para>Caches objects by keeping a soft reference to a cached object in order to
          enable the garbage collector to reclaim storage.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term><classname>PermanentObjectCacheImpl</classname></term>
        <listitem>
          <para>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&#39;t change during the lifetime of the application and are
          referenced often.</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </sect1>
  <sect1>
    <title>Dependencies on other packages</title>
    <variablelist>
      <varlistentry>
        <term>ojb.broker.metadata</term>
        <listitem>
          <para>This package uses exception <classname>ClassNotPersistenceCapableException</classname>
          from metadata.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>ojb.broker</term>
        <listitem>
          <para>This package uses the class <classname>Identity</classname> for storing
          objects. It also uses PersistenceBrokerFactory to retrieve the configuration.</para>
        </listitem>
      </varlistentry>
      <varlistentry>
        <term>ojb.broker.util</term>
        <listitem>
          <para>This package uses the logging facility.</para>
        </listitem>
      </varlistentry>
    </variablelist>
  </sect1>
  <sect1>
    <title>Hints for extending and maintaining this package</title>
    <sect2>
      <title>Adding a new type of cache</title>
      <para>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&#39;s assume that the name of the caching strategy is Foobar. Then you&#39;ve
      got to proceed as follows:</para>
      <orderedlist>
        <listitem>
          <para>Create a new class name <classname>FoobarObjectCacheImpl</classname> which
          implements <classname>ObjectCache</classname>.</para>
        </listitem>
        <listitem>
          <para>Implement all methods according to the method documentation for the
          methods of <classname>ObjectCache</classname>.</para>
        </listitem>
        <listitem>
          <para>Update the configuration files of OJB so that the application will use
          your newly written object cache.</para>
        </listitem>
      </orderedlist>
    </sect2>
  </sect1>
  <sect1>
    <title>ToDo</title>
    <orderedlist>
      <listitem>
        <para>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 <classname>Identy</classname> and <classname>PersistenceBrokerFactory.</classname>
        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(<classname>Object)</classname>).
        Removing the dependency on <classname>Identy</classname> removes the dependency on
        <classname>ClassNotPersistenceCapableException</classname> as well since this
        exception is thrown in the constructor of <classname>Identy.</classname></para>
        <para>The <classname>ObjectCacheFactory</classname> might get the configuration
        data from a static method of <classname>BaseConfiguration</classname> or some
        other class. This would remove the depency on ojb.broker entirely and making the
        object cache reusable.</para>
      </listitem>
    </orderedlist>
  </sect1>
</article>


