|
Copyright © 2008 BEA Systems, Inc. All Rights Reserved | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bea.p13n.cache.CacheFactory
public class CacheFactory
Factory to create Singleton Cache objects. This implementation can be used by clients running inside of the application context (eg, most EJBs) as well as clients running outside of that context (eg, JDBC Connection Pools).
The CacheFactory uses theCacheProvider
configured for each named cache
(or the default privider for the app) to retrieve Cache
implementations by name.
See getCacheProvider(String)
and getDefaultProviderId()
and getCache(String)
for descriptions of how the factory determines
which Cache providers are used.
Method Summary | |
---|---|
static boolean |
cacheExists(String cacheName)
Determine whether named cache exists (is known; that is, has been created). |
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 void |
flushKeys(String cacheName,
IKeySelector keySelector)
Flush the keys indicated by IKeySelector in the local
cache and in any cluster cache that may exist. |
static Cache |
getCache(String name)
Create or access an existing Cache . |
static String[] |
getCacheNames()
Returns the names of all known Caches. |
static CacheProvider |
getCacheProvider()
Return the default CacheProvider used by this factory. |
static CacheProvider |
getCacheProvider(String providerId)
Return a cache provider based on the provider id. |
static String |
getDefaultProviderId()
Return the id of the default provider. |
static void |
removeCache(String cacheName)
Clear and remove a cache from the system. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String[] getCacheNames()
public static boolean cacheExists(String cacheName)
public static Cache getCache(String name)
Cache
.
If the cache has been pre-configured, then create an
instance of a cache with those configured parameters and return it.
If the cache has not been pre-configured, then create a cache with default
parameters (defined in CacheDefaults
) and return it.
The cache will be creaed by the configured instance of the CacheProvider,
which may be configured on a per-named-cache basis (in p13n-cache-config.xml),
or by the configured default provider (See getDefaultProviderId()
).
If the cache exists already in the CacheFactory's collection (eg, it
has been created by a previous call to CacheFactory.getCache()), then
that same cache will be returned.
name
- the name of the cache to create or retrieve
CacheDefaults
public static void removeCache(String cacheName)
cacheName
- The name of the cache to remove.public static void flush(String cacheName, Serializable cacheKey)
Flushing a cache key will cause CacheFactory.getCache(cacheName).remove(cacheKey) to be called on each node in the cluster. Flushing an entire cache calls CacheFactory.removeCache(cacheName) on each cluster 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 in 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
cacheName
- the name of the cache to be flushedcacheKey
- the key in that cache to remove. If null, clear the
entire cache.flush(String)
public static void flush(String cacheName)
flush(cacheName,null)
.
public static String getDefaultProviderId()
P13nCacheProvider
is used as the default.
public static CacheProvider getCacheProvider()
getCacheProvider
( getDefaultProviderId()
() ).
public static CacheProvider getCacheProvider(String providerId)
getDefaultProviderId()
.
The first invocation of this method loads Cache providers as follows:
P13nCacheProvider
is always loaded.
getDefaultProviderId()
.
providerId
- the ID of the requested provider. Null indicates the default provider.
public static void flushKeys(String cacheName, IKeySelector keySelector)
IKeySelector
in the local
cache and in any cluster cache that may exist.
cacheName
- the name of the cache to be flushedkeySelector
- the set of keys to be flushed
|
Copyright © 2008 BEA Systems, Inc. All Rights Reserved | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |