A
CacheContainer is the primary mechanism for retrieving a {@link org.infinispan.Cache} instance, and is oftenused as a starting point to using the {@link org.infinispan.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 {@link #stop()} on the
CacheManager. This will ensure all cacheswithin 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");
@see org.infinispan.manager.EmbeddedCacheManager
@author Manik Surtani (
manik@jboss.org)
@author Galder ZamarreƱo
@author Mircea.Markus@jboss.com
@since 4.0