As explained in {@link org.exolab.castor.jdo.persist}, {@link org.exolab.castor.persist.LockEngine} implements a persistence engine that caches objects in memory for performance reasons and thus eliminates the number of operations against the persistence storage.

Author:
  Werner Guttmann

The main component of this package is the interface {@link Cache.java}, which declares the external functionality of a performance cache. Existing (and future) cache engines have to implement this interface, which is closely modelled after {@link java.util.Map}. To obtain an instance of a particular cache engine (from client code), client code is instructed to use {@link CacheRegistry} and its factory methods.

The remainder of this package are exceptions associated with cache interaction, an enumeration of all (currently) available cache types and a prototype for an (abstract) base class to assist future cache engine additions.

### Configuration

Castor (as of release 0.9.6) allows for addition of user-defined cache implementations.

By default, the file castor.properties includes a section as follows:

    #
    # Cache implementations
    #
    org.exolab.castor.jdo.cacheFactories=\
      org.exolab.castor.persist.cache.NoCacheFactory,\
      org.exolab.castor.persist.cache.TimeLimitedFactory,\
      org.exolab.castor.persist.cache.CountLimitedFactory,\
      org.exolab.castor.persist.cache.UnlimitedFactory

To add your own performance cache implementation, please append the fully-qualified class name to this list as shown here:

    #
    # Cache implementations
    #
    org.exolab.castor.jdo.cacheFactories=\
      org.exolab.castor.persist.cache.NoCacheFactory,\
      org.exolab.castor.persist.cache.TimeLimitedFactory,\
      org.exolab.castor.persist.cache.CountLimitedFactory,\
      org.exolab.castor.persist.cache.UnlimitedFactory,\
      org.whatever.somewhere.nevermind.CustomCache

In addition, you will have to provide the cache implementation and a CacheFactory implementation for your new cache instance. For this, please add an implementation of {@link CacheFactory} and make sure that you provide valid values for the two properties name and className.

To assist users in this task, a {@link AbstractCacheFactory} class has been supplied, which users should derive their custom {@link CacheFactory} instances from, if they wish so. Please consult existing {@link CacheFactory} implementations such as {@link TimeLimitedFactory} or {@link CountLimitedFactory} for code samples.

    /**
     * My own cache implementation
     */
     public class CustomCache extends AbstractBaseCache {

        ...

     }

    /**
     * My own cache factory implementation
     */
     public class CustomCacheFactory extends AbstractCacheFactory {

        /**
         * The name of the factory
         */
        private static final String NAME = "custom";

        /**
         * Full class name of the underlying cache implementation.
         */
        private static final String CLASS_NAME = "my.company.project.CustomCache";

        /**
         * Returns the short alias for this factory instance.
         * @return The short alias name.
         */
        public String getName()
        {
            return NAME;
        }

        /**
         * Returns the full class name of the underlying cache implementation.
         * @return The full cache class name.
         */
        public String getCacheClassName() {
            return CLASS_NAME;
        }

     }