Overview | Package | Class | Tree | Deprecated | Index | Help
| © 2005 BEA Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.bea.p13n.cache
Class CacheFactory

    java.lang.Object
      com.bea.p13n.cache.CacheFactory

public class CacheFactory
extends Object

Factory to create Singleton Cache objects. This implementation can be used by clients running inside of the CacheMBean application context (eg, most EJBs) as well as clients running outside of that context (eg, JDBC Connection Pools).

Constructor Summary
`CacheFactory()`

Method Summary
`static boolean` | `cacheExists(String cacheName)` Determine whether named cache exists in our collection
`static void` | `flush(String cacheName)` Performs a cluster-aware flush of a given cache.
`static void` | `flush(String cacheName, Serializable cacheKey)` Performs a cluster-aware flush of the given cache's key.
`static Cache` | `getCache(String name)` Create a new or access an existing Cache.
`static String[]` | `getCacheNames()` Returns all Cache names
`static void` | `removeCache(String cacheName)` Remove a cache from the system.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CacheFactory

    public CacheFactory()

Method Detail

### cacheExists

    public static boolean cacheExists(String cacheName)

  Determine whether named cache exists in our collection

  Returns:
    true if exists, false otherwise

### flush

    public static void flush(String cacheName)

  Performs a cluster-aware flush of a given cache. Flush causes the given cache to be cleared and removed, first locally (the cache on this node), and then on all other nodes of the cluster. Same as `flush(cacheName,null)`.

### flush

    public static void flush(String cacheName,
                             Serializable cacheKey)

  Performs a cluster-aware flush of the given cache's key. Flush causes the given key to be removed from the named cache, first locally (the cache on this node), and then on all other nodes of the cluster.

  Flushing a cache key will call `CacheFactory.getCache(cacheName).remove(cacheKey)` on each node in the cluster. Flushing an entire cache calls `CacheFactory.removeCache(cacheName)` on each node.

  The keys for caches to be flushed must be serializable so the key can be broadcast to other nodes. Cache entries with non-serializable keys can not be flushed this way.

  The assumption inherrent in this design is that each node will retrieve and cache its own data. When the "real" data (i.e. in a database) changes, you want to clear all caches, cluster-wide, so on next access the cache will be empty, causing that node to re-fetch the data from the store.

  The pattern for cached data that needs to be cluster-aware is something like:

        database.update( newData );  // change backing data
        CacheFactory.flush( "myCache", "myData" );  // cluster-wide flush
        CacheFactory.getCache( "myCache" ).put( "myData", newData );  // cache locally

  Parameters:
    `cacheName` - the name of the cache to be flushed
    `cacheKey` - the key in that cache to remove. If null, clear the entire cache.
  See Also:
    `flush(String)`

### getCache

    public static Cache getCache(String name)

  Create a new or access an existing Cache.

  If the cache has been pre-configured using MBeans, then create an instance of a cache with those parameters and return it. If the cache has not been pre-configured with MBeans, then create a cache with default parameters (defined in CacheDefaults) and return it.

  If the cache exists already in the CacheFactory's collection (eg, it has been created by a previous call to CacheFactory.getCache()), then return an instance of that named cache.

  Parameters:
    `name` - the name of the cache to create or retrieve
  Returns:
    the cache that was created or retrieved.
  See Also:
    `CacheDefaults`

### getCacheNames

    public static String[] getCacheNames()

  Returns all Cache names

### removeCache

    public static void removeCache(String cacheName)

  Remove a cache from the system. Clear cache before setting to null and removing it from our collection. Allows the Garbage Collector to clean up.

  Parameters:
    `cacheName` - The name of the cache to remove.

Overview | Package | Class | Tree | Deprecated | Index | Help
| © 2005 BEA Systems, Inc.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 BEA Systems, Inc. All Rights Reserved