From: Ben W. <bw...@us...> - 2004-08-31 06:55:37
|
User: bwang00 Date: 04/08/30 23:55:29 Modified: docs/html FAQ.html Log: Updated classloader faq Revision Changes Path 1.9 +28 -2 jboss-cache/docs/html/FAQ.html Index: FAQ.html =================================================================== RCS file: /cvsroot/jboss/jboss-cache/docs/html/FAQ.html,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- FAQ.html 27 Aug 2004 00:41:43 -0000 1.8 +++ FAQ.html 31 Aug 2004 06:55:28 -0000 1.9 @@ -7,7 +7,33 @@ tx.begin() tree.put(fqn, key, value); -tx.commit();</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e311"></a><a name="d0e312"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I control the cache locking level?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>JBossCache let you control the cache locking level through the transaction isolation level. This is configured through the attribute <tt class="literal">IsolationLevel</tt>. Currently, JBossCache employs pessimistic locking internally. And the transaction isolation level from the pessimist locking corresponds to JDBC isolation levels, namely, <tt class="literal">NONE</tt>, <tt class="literal">READ_UNCOMMITTED</tt>, <tt class="literal">READ_COMMITTED</tt>, <tt class="literal">REPEATABLE_READ</tt>, and <tt class="literal">SERIALIZABLE</tt>. For details, please refer to the user manual.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e336"></a><a name="d0e337"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I monitor and manage the JBossCache?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>If you are running JBossCache as a MBean service inside JBoss, you can monitor and manage through the jmx console. We plan to add more attributes such as cache hit/miss numbers in the future release.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e343"></a><a name="d0e344"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support partitioning?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not right now. JBossCache does not support partitioning that a user can configure to have different set of data residing on different cache instances while still participating as a replication group.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e350"></a><h3 class="title"><a name="d0e350"></a>3. TreeCacheAop</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e353"></a><a name="d0e354"></a><b>Q:</b></td><td align="left" valign="top"><p>What is TreeCacheAop?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>TreeCacheAop (currently implemented as a sub-class of TreeCache) is a replicated and transactional "object-oriented" cache. By "object-oriented", we mean that the cache: 1) automatically manages object mapping and relationship for a client under both local and replicated cache mode, 2) provides support for inheritance relationship between "advised" POJOs. By leveraging the dynamic AOP in JBossAop, it is able to map a complex object into the cache store, preserve and manage the object relationship behind the scene. During replication mode, it performs fine-granularity (i.e., on a per-field basis) update, and thus has the potential to boost cache performance and minimize network traffic.</p><p>From a user perspective, once the object is managed by the cache, all cache operations are transparent. Therefore, all the usual in-VM POJO method semantics are still preserved, providing ease of use. For example, if a POJO has been put in TreeCacheAop (by calling putObject, for example), then any get/set method will be intercepted by TreeCacheAop to provide the data from the cache.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e362"></a><a name="d0e363"></a><b>Q:</b></td><td align="left" valign="top"><p>Does TreeCacheAop have all the functional capabilities of TreeCache?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. TreeCacheAop extends TreeCache so it has all the same features TreeCache such as cache mode, transaction isolation level, and eviction policy.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e369"></a><a name="d0e370"></a><b>Q:</b></td><td align="left" valign="top"><p>What is the difference between TreeCache and TreeCacheAop?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Think of TreeCacheAop as a TreeCache on steroid. :-) Seriously, both are cache store. However, while TreeCache only provides pure object reference storage (e.g., <tt class="literal">put(FQN fqn, Objecy key, Object value)</tt>), TreeCacheAop goes behind that and performs object mapping and relationship management for a user behind the scene. As a result, if you have a complex object systems that you would like to cache, you can have TreeCacheAop manages for you. You simply treat your object systems as they are residing in-memory, e.g., use your regular POJO methods without worrying about cache management. Furthermore, this is true in replication mode as well.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e379"></a><a name="d0e380"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I pre-compile the aop classes such that I don't need to use the system classloader and jboss-aop configuration xml?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. The latest versions of JBossCache has a per-compiler option called <tt class="literal">aopc</tt>. You can use this option to pre-compile your "advised" POJO. Once the classes have been byte code generated, it can be treated as regular class files, i.e., you will not need to include any <tt class="literal">jboss-aop.xml</tt> that specifies the advisable POJO and to specify the JBossAop system class loader.</p><p>For an example of how to use <tt class="literal">aopc</tt>, please see the <tt class="literal">build.xml</tt> in the standalone package.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e400"></a><a name="d0e401"></a><b>Q:</b></td><td align="left" valign="top"><p>What's in the <tt class="literal">jboss-aop.xml</tt> configuration?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>In <tt class="literal">jboss-aop.xml</tt>, you declare your POJO (e.g., <tt class="literal">Person</tt> to be "prepared", a JBOssAop term to denote that the object will be "advised" by the system. After this declaration, JBossAop will invoke any interceptor that associates with this POJO. TreeCacheAop will dynamically add an <tt class="literal">org.jboss.cache.aop.CacheInterceptor</tt> to this POJO to perform object mapping and relationship management.</p><p>Note that to add your POJO, you should declare all the fields will be "advised" as in the example.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e421"></a><a name="d0e422"></a><b>Q:</b></td><td align="left" valign="top"><p>Is it possible to store the same object multiple time but with different paths? Like /foo/byName and /foo/byId ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes, you can use TreeCacheAop to do that. It supports the notion of object reference.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e428"></a><a name="d0e429"></a><b>Q:</b></td><td align="left" valign="top"><p>Do I need to declare all my objects "prepare" in <tt class="literal">jboss-aop.xml</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not necessarily. If there is some objects that you don't need the cache to manage it for you, you can leave it out of the declaration. The cache will treat this object as a "primitive" type. However, the object will need to implement <tt class="literal">Serializable</tt> interface though.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e441"></a><a name="d0e442"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I use <tt class="literal">List</tt>, <tt class="literal">Set</tt>, and <tt class="literal">Map</tt> dynamic proxy?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>TreeCacheAop supports classes extends from <tt class="literal">List</tt>, <tt class="literal">Set</tt>, and <tt class="literal">Map</tt> without users to declare it "advised". It is done via a dynamic proxy. Here is a code snippet to use an <tt class="literal">ArrayList</tt> class.</p><pre class="programlisting">ArrayList list = new ArrayList(); +tx.commit();</pre></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e311"></a><a name="d0e312"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I control the cache locking level?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>JBossCache let you control the cache locking level through the transaction isolation level. This is configured through the attribute <tt class="literal">IsolationLevel</tt>. Currently, JBossCache employs pessimistic locking internally. And the transaction isolation level from the pessimist locking corresponds to JDBC isolation levels, namely, <tt class="literal">NONE</tt>, <tt class="literal">READ_UNCOMMITTED</tt>, <tt class="literal">READ_COMMITTED</tt>, <tt class="literal">REPEATABLE_READ</tt>, and <tt class="literal">SERIALIZABLE</tt>. For details, please refer to the user manual.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e336"></a><a name="d0e337"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I monitor and manage the JBossCache?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>If you are running JBossCache as a MBean service inside JBoss, you can monitor and manage through the jmx console. We plan to add more attributes such as cache hit/miss numbers in the future release.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e343"></a><a name="d0e344"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support partitioning?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not right now. JBossCache does not support partitioning that a user can configure to have different set of data residing on different cache instances while still participating as a replication group.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e350"></a><a name="d0e351"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBosCache have concept of application classloading inside, say, a J2EE container?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Classloading is used widely inside J2EE container. For example, a web application may require a new classloader to scope a specific version of the user library. Unfortunately, JBossCache (or cache system in general) is agnostic to the classloader. In general, there are two problems involved:</p><div class="itemizedlist"><ul type="disc"><li><p>Object instance created by thread 1 and will be accessed by thread 2 (with two different classloaders). JBossCache has no notion of different class loaders involved. As a result, you will have a <tt class="literal">ClassCastException</tt>.</p></li><li><p>Object instance stored in cache1 and is replicated to cache2. As a result, the instance in cache2 is created by the system classloader. Now, a user thread in cache2 can't access it since the classloader may be different from the system one.</p></li></ul></div><p>To solve these issues, the only solution (that we know) is to cache "serialized" byte code and only de-serialize it during every object get (and this will be expensive!). That is, during put operation, the object instance will be serialized and therefore can be replicated safely. However, the performance penalty of this approach is quite severe so in general another local in-vm version will need to be used as a "near-line" cache.</p><p>JBoss has a utility class called <tt class="literal">MarshalledValue</tt> that wraps around the serialized object. Here is a code snippet that illustrates how you can create a wrapper around JBossCache to handle the classloader issue:</p><pre class="programlisting">import org.jboss.invocation.MarshalledValue; + +public class CacheService { + private TreeCache cache_; + + public object get(Fqn fqn, String key) { + return getUnMarshalledValue(cache_.get(fqn, key)); + } + + public object set(Fqn fqn, String key, Object value) { + cache_.put(fqn, key, getMarshalledValue(value)); + return value; // only if successful + } + +... + + private Object getUnMarshalledValue(object value) { + // assuming we use the calling thread context classloader + return ((MarshalledValue)value).get(); + } + + private Object getMarshalledValue(Object value) { + return new MarshalledValue(value); + } +} + +</pre></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e376"></a><h3 class="title"><a name="d0e376"></a>3. TreeCacheAop</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e379"></a><a name="d0e380"></a><b>Q:</b></td><td align="left" valign="top"><p>What is TreeCacheAop?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>TreeCacheAop (currently implemented as a sub-class of TreeCache) is a replicated and transactional "object-oriented" cache. By "object-oriented", we mean that the cache: 1) automatically manages object mapping and relationship for a client under both local and replicated cache mode, 2) provides support for inheritance relationship between "advised" POJOs. By leveraging the dynamic AOP in JBossAop, it is able to map a complex object into the cache store, preserve and manage the object relationship behind the scene. During replication mode, it performs fine-granularity (i.e., on a per-field basis) update, and thus has the potential to boost cache performance and minimize network traffic.</p><p>From a user perspective, once the object is managed by the cache, all cache operations are transparent. Therefore, all the usual in-VM POJO method semantics are still preserved, providing ease of use. For example, if a POJO has been put in TreeCacheAop (by calling putObject, for example), then any get/set method will be intercepted by TreeCacheAop to provide the data from the cache.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e388"></a><a name="d0e389"></a><b>Q:</b></td><td align="left" valign="top"><p>Does TreeCacheAop have all the functional capabilities of TreeCache?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. TreeCacheAop extends TreeCache so it has all the same features TreeCache such as cache mode, transaction isolation level, and eviction policy.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e395"></a><a name="d0e396"></a><b>Q:</b></td><td align="left" valign="top"><p>What is the difference between TreeCache and TreeCacheAop?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Think of TreeCacheAop as a TreeCache on steroid. :-) Seriously, both are cache store. However, while TreeCache only provides pure object reference storage (e.g., <tt class="literal">put(FQN fqn, Objecy key, Object value)</tt>), TreeCacheAop goes behind that and performs object mapping and relationship management for a user behind the scene. As a result, if you have a complex object systems that you would like to cache, you can have TreeCacheAop manages for you. You simply treat your object systems as they are residing in-memory, e.g., use your regular POJO methods without worrying about cache management. Furthermore, this is true in replication mode as well.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e405"></a><a name="d0e406"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I pre-compile the aop classes such that I don't need to use the system classloader and jboss-aop configuration xml?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. The latest versions of JBossCache has a per-compiler option called <tt class="literal">aopc</tt>. You can use this option to pre-compile your "advised" POJO. Once the classes have been byte code generated, it can be treated as regular class files, i.e., you will not need to include any <tt class="literal">jboss-aop.xml</tt> that specifies the advisable POJO and to specify the JBossAop system class loader.</p><p>For an example of how to use <tt class="literal">aopc</tt>, please see the <tt class="literal">build.xml</tt> in the standalone package.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e426"></a><a name="d0e427"></a><b>Q:</b></td><td align="left" valign="top"><p>What's in the <tt class="literal">jboss-aop.xml</tt> configuration?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>In <tt class="literal">jboss-aop.xml</tt>, you declare your POJO (e.g., <tt class="literal">Person</tt> to be "prepared", a JBOssAop term to denote that the object will be "advised" by the system. After this declaration, JBossAop will invoke any interceptor that associates with this POJO. TreeCacheAop will dynamically add an <tt class="literal">org.jboss.cache.aop.CacheInterceptor</tt> to this POJO to perform object mapping and relationship management.</p><p>Note that to add your POJO, you should declare all the fields will be "advised" as in the example.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e447"></a><a name="d0e448"></a><b>Q:</b></td><td align="left" valign="top"><p>Is it possible to store the same object multiple time but with different paths? Like /foo/byName and /foo/byId ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes, you can use TreeCacheAop to do that. It supports the notion of object reference.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e454"></a><a name="d0e455"></a><b>Q:</b></td><td align="left" valign="top"><p>Do I need to declare all my objects "prepare" in <tt class="literal">jboss-aop.xml</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not necessarily. If there is some objects that you don't need the cache to manage it for you, you can leave it out of the declaration. The cache will treat this object as a "primitive" type. However, the object will need to implement <tt class="literal">Serializable</tt> interface though.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e467"></a><a name="d0e468"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I use <tt class="literal">List</tt>, <tt class="literal">Set</tt>, and <tt class="literal">Map</tt> dynamic proxy?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>TreeCacheAop supports classes extends from <tt class="literal">List</tt>, <tt class="literal">Set</tt>, and <tt class="literal">Map</tt> without users to declare it "advised". It is done via a dynamic proxy. Here is a code snippet to use an <tt class="literal">ArrayList</tt> class.</p><pre class="programlisting">ArrayList list = new ArrayList(); list.add("first"); cache.putObject("/list/test", list); @@ -16,4 +42,4 @@ ArrayList myList = (List)cache.getObject("/list/test"); // we are getting a dynamic proxy instead myList.add("second"); // it works now myList.add("third"); -myList.remove("third");</pre></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e471"></a><h3 class="title"><a name="d0e471"></a>4. Eviction Policy</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e474"></a><a name="d0e475"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support eviction policy?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. JBossCache currently implements a LRU eviction policy for both TreeCache (<tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt>) and TreeCacheAop (<tt class="literal">org.jboss.cache.eviction.AopLRUPolicy</tt>). Users can also plug in their own eviction policy algorithms. See user manual for details.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e487"></a><a name="d0e488"></a><b>Q:</b></td><td align="left" valign="top"><p>Why can't I use <tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt> for TreeCacheAop as well?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>For TreeCacheAop, you will need to use <tt class="literal">org.jboss.cache.eviction.AopLRUPolicy</tt>) because AOP has its eviction algorithm, although is LRU but has totally different notion of an "object", for example.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e500"></a><a name="d0e501"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache's implemented LRU eviction policy operates in replication mode?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes and no. :-)</p><p>The LRU policy only operates in local mode. That is, nodes that are only evicted locally. This may cause the cache contents not to be synchronized temporarily. But when a user tries to obtain a cache content of an evicted node and finds out that is null (e.g., get returns null), it should get it from 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.</p><p>However, you still can run eviction policy with cache mode set to either <tt class="literal">REPL_SYNC</tt> or <tt class="literal">REPL_ASYNC</tt>. Depends on your use case, you can set multiple cache instances to have their own eviction policy (of which is operated locally) or just have selected instance with eviction policy activated.</p><p>Also note that, when the cache persistence layer is implemented in the next release, an locally evicted node can also be persisted to the backend store.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e519"></a><a name="d0e520"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support <tt class="literal">Region</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. JBossCache has the notion of region where a user can configure the eviction policy parameters (e.g., <tt class="literal">maxNodes</tt> or <tt class="literal">timeToIdelSeconds</tt> )</p><p>A region in JBossCache denotes a portion of tree hierarchy, e.g., a fully qualified name (<tt class="literal">FQN</tt>). For example, a user can define <tt class="literal">/org/jboss</tt> and <tt class="literal">/org/foocom</tt> as two separate regions. But note that you can configure the region programatically now, i.e., everything has to be configured through the xml file.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e546"></a><a name="d0e547"></a><b>Q:</b></td><td align="left" valign="top"><p>What are the <tt class="literal">EvictionPolicyConfig</tt> tag parameters for <tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>They are:</p><div class="table"><a name="d0e559"></a><p class="title"><b>Table 1. Parameters</b></p><table summary="Parameters" border="1"><colgroup><col><col></colgroup><tbody><tr><td>wakeUpIntervalInSeconds</td><td>Interval where the clean up thread wakes to process the sitting queue and sweep away the old data.</td></tr><tr><td>region</td><td>A area where each eviction policy parameters are specified. Note that it needs a minimum of <tt class="literal">/_default</tt> region.</td></tr><tr><td>maxNodes</td><td>Max number of nodes allowed in the eviction queue. 0 means no limit.</td></tr><tr><td>timeToIdleInSeconds</td><td>Age (in seconds) for the node to be evicted in the queue. 0 denotes no limit.</td></tr></tbody></table></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e587"></a><a name="d0e588"></a><b>Q:</b></td><td align="left" valign="top"><p>I have turned on the eviction policy, why do I still get "out of memeory" (OOM) exception?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>OOM can happen when the speed of cache access exceeds the speed of eviction policy handling timer. Eviction policy handler will wake up every <tt class="literal">wakeUpIntervalInSeconds</tt> seconds to process the eviction event queue. And the queue size is fixed at 20000 now. So when the queue size is full, it will create a backlog and cause OOM 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 <tt class="literal">wakeUpIntervaleInSeconds</tt> so the timer thread processes the queue more frequently.</p><p>We will also externalize the queue size so it will be configurable in the next release.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e602"></a><h3 class="title"><a name="d0e602"></a>5. CacheLoader</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e605"></a><a name="d0e606"></a><b>Q:</b></td><td align="left" valign="top"><p>What is a CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>A CacheLoader is the connection of JBossCache to a (persistent) data store. The CacheLoader is called by JBossCache to fetch data from a store when that data is not in the cache, and when modifications are made to data in the cache the CacheLoader is called to store those modifications back to the store.</p><p>In conjunction with eviction policies, JBossCache with a CacheLoader allows a user to maintain a bounded cache for a large backend datastore. Frequently used data is fetched from the datastore into the cache, and the least used data is evicted, in order to provide fast access to frequently accessed data. This is all configured through XML, and the programmer doesn't have to take care of loading and eviction.</p><p>JBossCache currently (July 2004) ships with 2 CacheLoader implementations:</p><div class="itemizedlist"><ul type="disc"><li><p>FileCacheLoader: this implementation uses the file system to store and retrieve data. JBossCache nodes are mapped to directories, subnodes to subdirectories etc. Attributes of a node are mapped to a file <tt class="literal">data</tt> inside the directory.</p></li><li><p>BdbjeCacheLoader: this implementation is based on the Sleepycat Java Edition database, a fast and efficient transactional database. It uses a single file for the entire store. Note that if you use Sleepycat's CacheLoader with JBossCache, and ship your product, you have to acquire a commercial license from Sleepycat, see <a href="#">http://www.sleepycat.com/jeforjbosscache</a> for details.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e630"></a><a name="d0e631"></a><b>Q:</b></td><td align="left" valign="top"><p>Are there other CacheLoaders ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>We plan to write a DB CacheLoader, using either JDBC, or an O/R mapper such as Hibernate. Once in place, JBossCache will be able to interface with relational databases.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e637"></a><a name="d0e638"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I write my own CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. A CacheLoader is a class implementing <tt class="literal">org.jboss.cache.loader.CacheLoader</tt>. It is configured via the XML file (see JBossCache and Tutorial documentation).</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e647"></a><a name="d0e648"></a><b>Q:</b></td><td align="left" valign="top"><p>Does a CacheLoader have to use a persistent store ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>No, a CacheLoader could for example fetch (and possibly store) its data from a webdav-capable webserver. Another example is a caching proxy server, which fetches contents from the web. Note that an implementation of CacheLoader may not implement the 'store' functionality in this case, but just the 'load' functionality.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e654"></a><a name="d0e655"></a><b>Q:</b></td><td align="left" valign="top"><p>What can I use a CacheLoader for ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Some applications:</p><div class="itemizedlist"><ul type="disc"><li><p>HTTP sessions can be persisted (besides being replicated by JBossCache). The CacheLoader can be configured to be shared, or unshared, meaning that every node in a cluster has its own local store. It is also possible to attach a CacheLoader to just <span class="emphasis"><em>one</em></span> of the nodes.</p></li><li><p>Simple persistence for POJOs. Use of JBossCacheAop and a local CacheLoader persist POJOs transparently into the store provided by the CacheLoader.</p></li><li><p>Highly available replicated and persisted data store. The service is up as long as at least 1 node is running, but even if all nodes are taken offline, when the first node is started again, the data previously saved will still be available (e.g. a shopping cart).</p></li><li><p>A caching web proxy (a la Squid): all data are contents of URLs, users access the proxy, and if the URL is not in the cache, the CacheLoader fetches it from the web. This could actually be a replicated and transactional version of Squid.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e678"></a><a name="d0e679"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I configure JBossCache with a CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Through XML: both the fully-qualified classname of the CacheLoader and its configuration string have to be given. JBossCache will then instantiate a CacheLoader. See JBossCache documentation for details.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e685"></a><a name="d0e686"></a><b>Q:</b></td><td align="left" valign="top"><p>Do I have to pay to use Sleepycat's CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not if you use it only for personal use. As soon as you distribute your product with BdbjeCacheLoader, you have to purchase a commercial license from Sleepycat. See details at <a href="#">http://www.sleepycat.com/jeforjbosscache</a>.</p></td></tr></tbody></table></div></div></body></html> \ No newline at end of file +myList.remove("third");</pre></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e497"></a><h3 class="title"><a name="d0e497"></a>4. Eviction Policy</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e500"></a><a name="d0e501"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support eviction policy?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. JBossCache currently implements a LRU eviction policy for both TreeCache (<tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt>) and TreeCacheAop (<tt class="literal">org.jboss.cache.eviction.AopLRUPolicy</tt>). Users can also plug in their own eviction policy algorithms. See user manual for details.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e513"></a><a name="d0e514"></a><b>Q:</b></td><td align="left" valign="top"><p>Why can't I use <tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt> for TreeCacheAop as well?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>For TreeCacheAop, you will need to use <tt class="literal">org.jboss.cache.eviction.AopLRUPolicy</tt>) because AOP has its eviction algorithm, although is LRU but has totally different notion of an "object", for example.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e526"></a><a name="d0e527"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache's implemented LRU eviction policy operates in replication mode?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes and no. :-)</p><p>The LRU policy only operates in local mode. That is, nodes that are only evicted locally. This may cause the cache contents not to be synchronized temporarily. But when a user tries to obtain a cache content of an evicted node and finds out that is null (e.g., get returns null), it should get it from 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.</p><p>However, you still can run eviction policy with cache mode set to either <tt class="literal">REPL_SYNC</tt> or <tt class="literal">REPL_ASYNC</tt>. Depends on your use case, you can set multiple cache instances to have their own eviction policy (of which is operated locally) or just have selected instance with eviction policy activated.</p><p>Also note that, when the cache persistence layer is implemented in the next release, an locally evicted node can also be persisted to the backend store.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e545"></a><a name="d0e546"></a><b>Q:</b></td><td align="left" valign="top"><p>Does JBossCache support <tt class="literal">Region</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. JBossCache has the notion of region where a user can configure the eviction policy parameters (e.g., <tt class="literal">maxNodes</tt> or <tt class="literal">timeToIdelSeconds</tt> )</p><p>A region in JBossCache denotes a portion of tree hierarchy, e.g., a fully qualified name (<tt class="literal">FQN</tt>). For example, a user can define <tt class="literal">/org/jboss</tt> and <tt class="literal">/org/foocom</tt> as two separate regions. But note that you can configure the region programatically now, i.e., everything has to be configured through the xml file.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e572"></a><a name="d0e573"></a><b>Q:</b></td><td align="left" valign="top"><p>What are the <tt class="literal">EvictionPolicyConfig</tt> tag parameters for <tt class="literal">org.jboss.cache.eviction.LRUPolicy</tt>?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>They are:</p><div class="table"><a name="d0e585"></a><p class="title"><b>Table 1. Parameters</b></p><table summary="Parameters" border="1"><colgroup><col><col></colgroup><tbody><tr><td>wakeUpIntervalInSeconds</td><td>Interval where the clean up thread wakes to process the sitting queue and sweep away the old data.</td></tr><tr><td>region</td><td>A area where each eviction policy parameters are specified. Note that it needs a minimum of <tt class="literal">/_default</tt> region.</td></tr><tr><td>maxNodes</td><td>Max number of nodes allowed in the eviction queue. 0 means no limit.</td></tr><tr><td>timeToIdleInSeconds</td><td>Age (in seconds) for the node to be evicted in the queue. 0 denotes no limit.</td></tr></tbody></table></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e613"></a><a name="d0e614"></a><b>Q:</b></td><td align="left" valign="top"><p>I have turned on the eviction policy, why do I still get "out of memeory" (OOM) exception?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>OOM can happen when the speed of cache access exceeds the speed of eviction policy handling timer. Eviction policy handler will wake up every <tt class="literal">wakeUpIntervalInSeconds</tt> seconds to process the eviction event queue. And the queue size is fixed at 20000 now. So when the queue size is full, it will create a backlog and cause OOM 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 <tt class="literal">wakeUpIntervaleInSeconds</tt> so the timer thread processes the queue more frequently.</p><p>We will also externalize the queue size so it will be configurable in the next release.</p></td></tr><tr class="qandadiv"><td align="left" valign="top" colspan="2"><a name="d0e628"></a><h3 class="title"><a name="d0e628"></a>5. CacheLoader</h3></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e631"></a><a name="d0e632"></a><b>Q:</b></td><td align="left" valign="top"><p>What is a CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>A CacheLoader is the connection of JBossCache to a (persistent) data store. The CacheLoader is called by JBossCache to fetch data from a store when that data is not in the cache, and when modifications are made to data in the cache the CacheLoader is called to store those modifications back to the store.</p><p>In conjunction with eviction policies, JBossCache with a CacheLoader allows a user to maintain a bounded cache for a large backend datastore. Frequently used data is fetched from the datastore into the cache, and the least used data is evicted, in order to provide fast access to frequently accessed data. This is all configured through XML, and the programmer doesn't have to take care of loading and eviction.</p><p>JBossCache currently (July 2004) ships with 2 CacheLoader implementations:</p><div class="itemizedlist"><ul type="disc"><li><p>FileCacheLoader: this implementation uses the file system to store and retrieve data. JBossCache nodes are mapped to directories, subnodes to subdirectories etc. Attributes of a node are mapped to a file <tt class="literal">data</tt> inside the directory.</p></li><li><p>BdbjeCacheLoader: this implementation is based on the Sleepycat Java Edition database, a fast and efficient transactional database. It uses a single file for the entire store. Note that if you use Sleepycat's CacheLoader with JBossCache, and ship your product, you have to acquire a commercial license from Sleepycat, see <a href="#">http://www.sleepycat.com/jeforjbosscache</a> for details.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e656"></a><a name="d0e657"></a><b>Q:</b></td><td align="left" valign="top"><p>Are there other CacheLoaders ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>We plan to write a DB CacheLoader, using either JDBC, or an O/R mapper such as Hibernate. Once in place, JBossCache will be able to interface with relational databases.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e663"></a><a name="d0e664"></a><b>Q:</b></td><td align="left" valign="top"><p>Can I write my own CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Yes. A CacheLoader is a class implementing <tt class="literal">org.jboss.cache.loader.CacheLoader</tt>. It is configured via the XML file (see JBossCache and Tutorial documentation).</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e673"></a><a name="d0e674"></a><b>Q:</b></td><td align="left" valign="top"><p>Does a CacheLoader have to use a persistent store ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>No, a CacheLoader could for example fetch (and possibly store) its data from a webdav-capable webserver. Another example is a caching proxy server, which fetches contents from the web. Note that an implementation of CacheLoader may not implement the 'store' functionality in this case, but just the 'load' functionality.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e680"></a><a name="d0e681"></a><b>Q:</b></td><td align="left" valign="top"><p>What can I use a CacheLoader for ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Some applications:</p><div class="itemizedlist"><ul type="disc"><li><p>HTTP sessions can be persisted (besides being replicated by JBossCache). The CacheLoader can be configured to be shared, or unshared, meaning that every node in a cluster has its own local store. It is also possible to attach a CacheLoader to just <span class="emphasis"><em>one</em></span> of the nodes.</p></li><li><p>Simple persistence for POJOs. Use of JBossCacheAop and a local CacheLoader persist POJOs transparently into the store provided by the CacheLoader.</p></li><li><p>Highly available replicated and persisted data store. The service is up as long as at least 1 node is running, but even if all nodes are taken offline, when the first node is started again, the data previously saved will still be available (e.g. a shopping cart).</p></li><li><p>A caching web proxy (a la Squid): all data are contents of URLs, users access the proxy, and if the URL is not in the cache, the CacheLoader fetches it from the web. This could actually be a replicated and transactional version of Squid.</p></li></ul></div></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e704"></a><a name="d0e705"></a><b>Q:</b></td><td align="left" valign="top"><p>How do I configure JBossCache with a CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Through XML: both the fully-qualified classname of the CacheLoader and its configuration string have to be given. JBossCache will then instantiate a CacheLoader. See JBossCache documentation for details.</p></td></tr><tr class="question"><td align="left" valign="top"><a name="d0e711"></a><a name="d0e712"></a><b>Q:</b></td><td align="left" valign="top"><p>Do I have to pay to use Sleepycat's CacheLoader ?</p></td></tr><tr class="answer"><td align="left" valign="top"><b>A:</b></td><td align="left" valign="top"><p>Not if you use it only for personal use. As soon as you distribute your product with BdbjeCacheLoader, you have to purchase a commercial license from Sleepycat. See details at <a href="#">http://www.sleepycat.com/jeforjbosscache</a>.</p></td></tr></tbody></table></div></div></body></html> \ No newline at end of file |