License     Codehaus     OpenEJB     OpenJMS     OpenORB     Tyrex     

Old releases
  General
  Release 1.3
  Release 1.3rc1
  Release 1.2

Main
  Home
  About
  Features
  Download
  Dependencies
  Reference guide
  Publications
  JavaDoc
  Maven 2 support
  Maven 2 archetypes
  DTD & Schemas
  Recent HTML changes
  News Archive
  RSS news feed
  Project Wiki

Development/Support
  Mailing Lists
  SVN/JIRA
  Contributing
  Support
  Continuous builds
  Prof. services

Related projects
  Spring ORM support
  Spring XML factories
  WS frameworks

XML
  XML

XML Code Generator
  XML Code Generator

JDO
  Introduction
  First steps
  Using JDO
  JDO Config
  Types
  JDO Mapping
  JDO FAQ
  JDO Examples
  JDO HOW-TOs
  Tips & Tricks
  Other Features
  JDO sample JAR

Tools
  Schema generator

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

DDL Generator
  Using DDL Generator
  Properties
  Ant task
  Type Mapping

More
  The Examples
  3rd Party Tools
  JDO Tests
  XML Tests
  Configuration
 
 

About
  License
  User stories
  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.castor.cache.Factories=\
  org.castor.cache.simple.NoCacheFactory,\
  org.castor.cache.simple.TimeLimitedFactory,\
  org.castor.cache.simple.CountLimitedFactory,\
  org.castor.cache.simple.UnlimitedFactory,\
  org.castor.cache.distributed.FKCacheFactory,\
  org.castor.cache.distributed.JcsCacheFactory,\
  org.castor.cache.distributed.JCacheFactory,\
  org.castor.cache.distributed.CoherenceCacheFactory,\
  org.castor.cache.distributed.OsCacheFactory,\
  org.castor.cache.hashbelt.FIFOHashbeltFactory,\
  org.castor.cache.hashbelt.LRUHashbeltFactory
            

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

# 
# Cache implementations
# 
org.castor.cache.Factories=\
  org.castor.cache.simple.NoCacheFactory,\
  org.castor.cache.simple.TimeLimitedFactory,\
  org.castor.cache.simple.CountLimitedFactory,\
  org.castor.cache.simple.UnlimitedFactory,\
  org.castor.cache.distributed.FKCacheFactory,\
  org.castor.cache.distributed.JcsCacheFactory,\
  org.castor.cache.distributed.JCacheFactory,\
  org.castor.cache.distributed.CoherenceCacheFactory,\
  org.castor.cache.distributed.OsCacheFactory,\
  org.castor.cache.hashbelt.FIFOHashbeltFactory,\
  org.castor.cache.hashbelt.LRUHashbeltFactory,\
  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.