org.infinispan.manager
Interface CacheContainer

All Superinterfaces:
Lifecycle
All Known Subinterfaces:
CacheManager, EmbeddedCacheManager
All Known Implementing Classes:
DefaultCacheManager, RemoteCacheManager

public interface CacheContainer
extends Lifecycle

A CacheContainer is the primary mechanism for retrieving a Cache instance, and is often used as a starting point to using the Cache.

CacheManagers are heavyweight objects, and we foresee no more than one CacheManager being used per JVM (unless specific configuration requirements require more than one; but either way, this would be a minimal and finite number of instances).

You obtain Cache instances from the CacheManager by using one of the overloaded getCache(), methods. Note that with getCache(), there is no guarantee that the instance you get is brand-new and empty, since caches are named and shared. Because of this, the CacheManager also acts as a repository of Caches, and is an effective mechanism of looking up or creating Caches on demand.

When the system shuts down, it should call Lifecycle.stop() on the CacheManager. This will ensure all caches within its scope are properly stopped as well.

NB: Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to ensure that at least one but only one caller calls stop() on the cache, and it does so with the awareness that others may be using the cache.

Sample usage: CacheManager manager = new DefaultCacheManager("my-config-file.xml"); Cache entityCache = manager.getCache("myEntityCache"); entityCache.put("aPerson", new Person());

Configuration myNewConfiguration = new Configuration(); myNewConfiguration.setCacheMode(Configuration.CacheMode.LOCAL); manager.defineConfiguration("myLocalCache", myNewConfiguration); Cache localCache = manager.getCache("myLocalCache");

Since:
4.0
Author:
Manik Surtani (manik@jboss.org), Galder ZamarreƱo, Mircea.Markus@jboss.com
See Also:
EmbeddedCacheManager

Field Summary
static String DEFAULT_CACHE_NAME
           
 
Method Summary
<K,V> Cache<K,V>
getCache()
          Retrieves the default cache associated with this cache container.
<K,V> Cache<K,V>
getCache(String cacheName)
          Retrieves a named cache from the system.
 
Methods inherited from interface org.infinispan.lifecycle.Lifecycle
start, stop
 

Field Detail

DEFAULT_CACHE_NAME

static final String DEFAULT_CACHE_NAME
See Also:
Constant Field Values
Method Detail

getCache

<K,V> Cache<K,V> getCache()
Retrieves the default cache associated with this cache container.

As such, this method is always guaranteed to return the default cache.

NB: Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to ensure that at least one but only one caller calls stop() on the cache, and it does so with the awareness that others may be using the cache.

Returns:
the default cache.

getCache

<K,V> Cache<K,V> getCache(String cacheName)
Retrieves a named cache from the system. If the cache has been previously created with the same name, the running cache instance is returned. Otherwise, this method attempts to create the cache first.

In the case of a EmbeddedCacheManager: when creating a new cache, this method will use the configuration passed in to the EmbeddedCacheManager on construction, as a template, and then optionally apply any overrides previously defined for the named cache using the EmbeddedCacheManager.defineConfiguration(String, org.infinispan.config.Configuration) or EmbeddedCacheManager.defineConfiguration(String, String, org.infinispan.config.Configuration) methods, or declared in the configuration file.

NB: Shared caches are supported (and in fact encouraged) but if they are used it's the users responsibility to ensure that at least one but only one caller calls stop() on the cache, and it does so with the awareness that others may be using the cache.

Parameters:
cacheName - name of cache to retrieve
Returns:
a cache instance identified by cacheName

-->

Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.