Cache Frequently Asked Questions
for Use with JBoss Enterprise Application Platform 5
JBoss Cache is deprecated and will be removed in a future major release of JBoss Enterprise Application Platform.
Chapter 1. General Information
- Q: What is JBoss Cache?
- Q: Who are the JBoss Cache developers?
- Q: How do I know the version of JBoss Cache that I am using?
- Q: How can I migrate my application and configuration from using JBoss Cache 1.x to 2.x?
- Q: What about from 2.x to 3.x?
org.jboss.cache.Cacheinterface) is the underlying library that organizes data in a tree-like structure and handles all locking, passivation, eviction and replication characteristics of data in the cache. The POJO library (using the
org.jboss.cache.pojo.PojoCacheinterface) is built atop the core library and allows introspection of objects in the cache providing transparent coherence by using JBoss AOP. Note that the POJO edition of JBoss Cache (often referred to as POJO Cache) comes with a separate set of documentation (POJO Cache User Guide, FAQ, etc.) available on the JBoss Cache documentation website.
java -jar jbosscache-core.jarwill print version details.
Chapter 2. JBoss Cache: Core
- Q: Can I run multiple JBoss Cache instances on the same VM?
- Q: Can JBoss Cache run as a second level cache inside Hibernate?
- Q: What about using POJO Cache as a Hibernate cache?
- Q: How can I configure JBoss Cache?
- Q: Can I use a schema or DTD to validate my JBoss Cache configuration file?
- Q: What is the difference between the different cache modes?
- Q: How does JBoss Cache's replication mechanism work?
- Q: I run a 2-node cluster. If the network dies, do the caches continue to run?
- Q: Can I plug in library X instead of JGroups to handle remote calls and group communications?
- Q: Does the cache need to replicate to every other instance in the cluster? Is not this slow if the cluster is large?
- Q: I'm using Buddy Replication. Do I need to have some form of session affinity?
- Q: If I have the need for different configuration properties (e.g., CacheMode and IsolationLevel), do I simply need to create multiple org.jboss.cache.Cache instances with the appropriate configuration?
- Q: Is not this expensive from a networking standpoint, i.e., needing to create sockets for each org.jboss.cache.Cache instance?
- Q: Does the ClusterName configuration element have any relation to the EAP cluster PartitionName?
- Q: When using multiple JGroups based components (cluster-service.xml, cache [multiple instances]), what is the correct/valid way to configure those components to make sure my multicast addresses do not conflict?
- Q: Does JBoss Cache support cache persistence storage?
- Q: Does JBoss Cache support cache passivation/overflow to a data store?
- Q: Is JBoss Cache thread safe?
- Q: Does JBoss Cache support XA (2PC) transactions now?
- Q: Which transaction managers are supported by JBoss Cache?
- Q: How do I set up the cache to be transactional?
- Q: How do I control the Cache locking level?
- Q: How does JBoss Cache lock data for concurrent access?
- Q: How do I enable Optimistic Locking or MVCC in JBoss Cache?
- Q: Can I use the cache locking level even without a transaction context?
- Q: Does JBoss Cache support SELECT FOR UPDATE semantics?
- Q: With replication (REPL_SYNC/REPL_ASYNC) or invalidation (INVALIDATION_SYNC/INVALIDATION_ASYNC), how often does the cache broadcast messages over the network?
- Q: How can I do a mass removal?
- Q: Can I monitor and manage the JBoss Cache?
- Q: JBoss Cache uses a ":" character in its object name. This causes problems with my MBean server. What can I do about it?
- Q: Can I disable JBoss Cache management attributes?
- Q: What happened to jboss-serialization.jar?
- Q: Does JBoss Cache support partitioning?
- Q: Does JBoss Cache handle the concept of application classloading inside, say, a Java EE container?
- Q: Does JBoss Cache currently support pre-event and post-event notification?
- Q: How do I implement a custom listener to listen to cache events?
- Q: Can I use the UseRegionBasedMarshalling attribute in JBoss Cache in order to get around ClassCastExceptions happening when accessing data in the cache that has just been redeployed?
org.jboss.cache.config.Configurationobject, passed in to the
INVALIDATION_ASYNC. If you want to run JBoss Cache as a single instance, then you should set the cache mode to
LOCALso that it will not attempt to replicate anything. If you want to have synchronous replication among different JBoss Cache instances, you set it to
REPL_SYNC. For asynchronous replication, use
AYSNC_REPL. If you do not wish to replicate cached data but simply inform other caches in a cluster that data under specific addresses are now stale and should be evicted from memory, use
INVALIDATION_ASYNC. Synchronous and asynchronous behavior applies to invalidation as well as replication.
INVALIDATION_ASYNCare non-blocking. This can be useful when you want to have another JBoss Cache serving as a mirror or backup and you do not want to wait for confirmation that this mirror has received your messages.
cluster name). There is also an option of whether to populate the cache data upon starting a new instance in the
REPL_SYNCis used, operations will fail while if
REPL_ASYNCis used they will succeed. Even if they succeed though, caches will be out of sync.
IsolationLevel), do I simply need to create multiple
org.jboss.cache.Cacheinstances with the appropriate configuration?
ClusterNameconfiguration element have any relation to the EAP cluster
cluster-service.xml, cache [multiple instances]), what is the correct/valid way to configure those components to make sure my multicast addresses do not conflict?
org.jboss.cache.transaction.DummyTransactionManager), we do not recommend using this for production. It is not thread safe, and is intended for internal testing only.
org.jboss.cache.transaction.TransactionManagerLookupinterface, and return an instance of your
javax.transaction.TransactionManagerimplementation. The configuration property
TransactionManagerLookupClassdefines the class to be used by the cache to fetch a reference to a transaction manager. It is trivial to implement this interface to support other transaction managers. Once this attribute is specified, the cache will look up the transaction context from this transaction manager.
org.jboss.cache.transaction.GenericTransactionManagerLookupclass that ships with JBoss Cache is able to detect and bind to most popular transaction managers. See the
GenericTransactionManagerLookupJavadocs for more information.
IsolationLevel. The transaction isolation levels correspond to database isolation levels, namely
SERIALIZABLE. Note that these isolation levels are ignored if optimistic locking is used. For details, please refer to the JBoss Cache User Guide.
REPEATABLE_READare supported. Any other isolation level provided will either be upgraded or downgraded accordingly.
SELECT FOR UPDATEsemantics?
PESSIMISTICas your node locking scheme.
SELECT FOR UPDATEsemantics, simply do:
// start transaction ... cache.getInvocationContext().getOptionOverrides().setForceWriteLock(true); Node n = cache.get("/a/b/c"); // this acquires a WRITE LOCK on this node ... ... // end transaction
REPL_ASYNC) or invalidation (
INVALIDATION_ASYNC), how often does the cache broadcast messages over the network?
cache.removeNode("/myroot"), it will recursively remove all the entries under "/myroot".
jconsoleutility. See the chapter titled Management Information in the JBoss Cache User Guide for more details.
:" character in its object name. This causes problems with my MBean server. What can I do about it?
jboss.cache:service=JBossCacheas a prefix to all objects it binds in JMX. To work around this, use the
-Djbosscache.jmx.prefixJVM parameter to pass in an alternate prefix.
- Object instance is stored in cache1 and replicated to cache2. As a result, the instance in cache2 is created by the system classloader. The replication may fail if the system classloader on cache2 does not have access to the required class. Even if replication does not fail, a user thread in cache2 may not be able to access the object if the user thread is expecting a type defined by the application classloader.
- Object instance is created by thread 1 and will be accessed by thread 2 (with two different classloaders). JBoss Cache has no notion of the different classloaders involved. As a result, you will have a
ClassCastException. This is a standard problem in passing an object from one application space to another; JBoss Cache just adds a level of indirection in passing the object.
CacheMarshaller. Basically, this allows application code to register a classloader with a portion of the cache tree for use in handling objects replicated to that portion. See the
CacheMarshallersection of the JBoss Cache User Guide for more details.
UseLazyDeserializationconfiguration option in JBoss Cache, which wraps your objects in a
MarshalledValueserializes and deserializes your object on demand, ensuring the proper thread local context class loader is used each time.
org.jboss.cache.notifications.annotations.CacheListenerannotation for details.
UseRegionBasedMarshallingattribute in JBoss Cache in order to get around ClassCastExceptions happening when accessing data in the cache that has just been redeployed?
ServletContextListener, you could add this code into an
MBeanthat contained life cycle methods, such as
stop(). The key would be for this MBean to depend on the target cache, so that it can operate as long as the cache is up and running.
Chapter 3. Eviction Policies
- Q: Does JBoss Cache support eviction policies?
- Q: Does JBoss Cache's eviction policy operate in replication mode?
- Q: Does JBoss Cache support Region?
- Q: I have turned on the eviction policy. Why do I still get an Out of Memory (OOM) exception?
getreturns null), it should get it from the other data source and re-populate the data in the cache. During this moment, the node content will be propagated and the cache content will be in sync.
REPL_ASYNC. Depending on your use case, you can set multiple cache instances to have their own eviction policy (which are applied locally) or just have selected instances with eviction policies activated.
org.jboss.cache.Fqn). For example, a user can define
/org/foocomas two separate regions. But note that you can configure the region programmatically now, i.e., everything has to be configured through the XML file.
wakeUpIntervalSecondsseconds, prior to 3.x) to process the eviction event queue. So when the queue size is full, it will create a backlog and cause out-of-memory exceptions to happen unless the eviction timer catches up. To address this problem, in addition to increase the VM heap size, you can also reduce the
wakeUpIntervalso the timer thread processes the queue more frequently.
Chapter 4. Cache Loaders
- Q: What is a cache loader?
- Q: Is the FileCacheLoader recommended for production use?
- Q: Can writing to cache loaders be asynchronous?
- Q: Can I write my own cache loader?
- Q: Does a cache loader have to use a persistent store?
- Q: Can I use more than one cache loader?
- Q: Can I migrate a JDBCacheLoader or FileCacheLoader based cache store containing data formatted with JBoss Cache 1.x.x to JBoss Cache 2.0 format?
- Q: Is the TCPDelegatingCacheLoader resilient to TCPCacheServer restarts?
org.jboss.cache.loader.FileCacheLoader: this implementation uses the file system to store and retrieve data. JBoss Cache nodes are mapped to directories, subnodes to subdirectories, etc. Attributes of a node are mapped to a data file inside the directory.
org.jboss.cache.loader.jdbm.JdbmCacheLoader: this implementation is based on JDBM, an open source file-based transactional persistence engine.
org.jboss.cache.loader.bdbje.BdbjeCacheLoader: this implementation is based on Oracle's Berkeley DB Java Edition database, a fast and efficient transactional database. It uses a single file for the entire store. Note that if you use the Berkeley DB cache loader with JBoss Cache and wish to ship your product, you will have to acquire a commercial license from Oracle.
org.jboss.cache.loader.JDBCCacheLoader: this implementation uses the relational database as the persistent storage.
- And more. See the chapter on cache loaders in the JBoss Cache User Guide for more details.
- Due to the way the FileCacheLoader represents a tree structure on disk (directories and files) traversal is inefficient for deep trees.
- Usage on shared file systems like NFS, Windows shares, etc. should be avoided as these do not implement proper file locking and can cause data corruption.
- Usage with an isolation level of NONE can cause corrupt writes as multiple threads attempt to write to the same file.
- File systems are inherently not transactional, so when attempting to use your cache in a transactional context, failures when writing to the file (which happens during the commit phase) cannot be recovered.
asyncattribute to true. See the JBoss Cache Users' Guide for a more detailed discussion. By default though, all cache loader writes are synchronous and will block.
org.jboss.cache.loader.AbstractCacheLoader. It is configured via the XML file (see JBoss Cache User Guide).
Chapter 5. Troubleshooting
- Q: I am having problems getting JBoss Cache to work, where can I get information on troubleshooting?
Appendix A. Revision History
|Revision 5.2.0-100||Wed 23 Jan 2013|
|Revision 5.1.2-100||Thu Dec 8 2011|
|Revision 5.1.1-100||Mon Jul 18 2011|
|Revision 5.1.0-100||Wed Sep 15 2010|