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

  



Caching

Reference: API documentation


News
Introduction
Configuration
    CacheFactory implementation
    Cache implementation
CacheManager - monitoring and clearing caches


News

Release 0.9.6:

-Added information about inquiring whether objects are cached (or not) to the CacheManager section.
-Added a section about (selectively) expiring caches, using the CacheManager interface.

Introduction

As explained in API docs for the persists package, LockEngine implements a persistence engine that caches objects in memory for performance reasons and thus eliminates the number of operations against the persistence storage.

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

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 implementations of Cache and CacheFactory for your new cache instance.

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

For this, 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 code samples.

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

CacheManager - monitoring and clearing caches

Sometimes it is necessary to interact with Castor's performance caches to e.g. (selectively) clear a Castor performance cache of its content, or inquire about whether a particular object instance (as identified by its identity) is cached already.

For this purpose a CacheManager can be obtained from a Database instance by issuing the following code:

	     
JDO jdo = ....;
Database db = jdo.getDatabase();
CacheManager manager = ((DatabaseImpl) db.getCacheManager();
	     

This instance can subsequently be used to selectively clear the Castor performance cache using one of the following methods:

-expireCache()
-expireCache(Class,Object)
-expireCache(Class,Object[])
-expireCache(Class[])

To inquire whether an object has already been cached, please use the following method:

-isCached (Class, Object);

Please note that once you have closed the Database instance from which you have obtained the CacheManager, the CacheManager cannot be used anymore and will throw a PersistenceException.

 
   
  
   
 


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.