Codehaus     ExoLab     OpenEJB     OpenJMS     OpenORB     Castor     Tyrex     
 

Main
  Home
  About
  Features
  Download
  API
  Schema
  Castor Forums
  Mailing Lists
  CVS / JIRA
  Support
  CastorWiki
  RSS news feed

XML
  Using XML
  Source Generator
  Schema Support
  XML Mapping
  XML FAQ
  Custom Handlers

JDO
  Introduction
  Using JDO
  JDO Config
  Types
  JDO Mapping
  JDO FAQ
  JDO Examples
  JDO How-Tos
  Other Features

Advanced JDO
  OQL
  Trans. & Locks
  Design
  KeyGen
  Long Trans.
  Nested Attrs.
  Pooling Examples
  LOBs
  Best practice

More
  Presentations
  The Examples
  3rd Party Tools
  JDO Tests
  XML Tests
  Configuration
  Tips & Tricks
  Full JavaDoc
  CastorWiki
  
  

About
  License
  Contributors
  Marketplace
  Status, Todo
  Changelog
  Library
  Contact
  Project Name

  



How to create a custom cache provider


Introduction
Intended audience
Steps
    Configuration
    Cache provider implementation
        CacheFactory implementation
        Cache implementation
References


Introduction

In the context of a relational data-binding tool such as Castor JDO, caches enhance application performance by reducing the number of read operations against the persistence storage, by storing and reusing the last read or committed values of the object.

Castor provides a set of pre-built cache providers, offering a variety of different cache algorithms. Nevertheless, special needs might require the application developer to implement a custom cache algorithm.

Castor facilitates such need by making available a standardized process of how to integrate a custom cache provider.

Intended audience

Anyone who wants to develop his own custom cache provider and integrate it with Castor JDO.

Steps

The main component of Castor's cache system is the interface Cache, which declares required functionality of a performance cache provider. Existing (and future) cache implementations have to implement this interface, which is closely modelled after java.util.Map.

Below are defined the steps to build a custom cache provider and register it with Castor JDO.

Configuration

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

By default, performance caches are registered with Castor JDO through it's main configuratoin file castor.properties. This file 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 provider, 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
            

Cache provider implementation

You will have to provide implementations of the interfaces Cache and CacheFactory for your new cache provider.

CacheFactory implementation

For this, please add an implementation of CacheFactory and make sure that you provide valid values for the two properties name and className.

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

    /**
     * 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;   
        }
        
     }
              

Cache implementation

Please create an implementation of Cache.

To assist users in this task, a AbstractBaseCache class has been supplied, which users should derive their custom Cache instances from, if they wish so. Please consult existing Cache implementations such as TimeLimited} or CountLimited for complete code samples.

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

References

-Performance caches
 
   
  
   
 


Copyright ? 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved.
 
Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners.