User development, A new message was posted in the thread "How to manage empty data with a CacheLoader?":
http://community.jboss.org/message/525362#525362 Author : Nicolas Filotto Profile : http://community.jboss.org/people/nfilotto Message: -------------------------------------------------------------- To solve my issue I had to write a decorator on the top of the current CacheLoader in order to rewrite the methods corresponding to read operations. Since I load everything at startup, I can by-pass the CacheLoader call when the cache is started. See below the code: {code:java} public class ControllerCacheLoader implements CacheLoader { /** * The nested cache loader */ private final CacheLoader cl; ... /** * @see org.jboss.cache.loader.CacheLoader#exists(org.jboss.cache.Fqn) */ public boolean exists(Fqn name) throws Exception { if (cache.getCacheStatus() == CacheStatus.STARTING) { // Before calling the nested cache loader we first check if the data exists in the local cache // in order to prevent multiple call to the cache store NodeSPI<?, ?> node = cache.peek(name, false); if (node != null) { // The node already exists in the local cache, so we return true return true; } else { // The node doesn't exist in the local cache, so we need to check through the nested // cache loader return cl.exists(name); } } // All the data is loaded at startup, so no need to call the nested cache loader for another // cache status other than CacheStatus.STARTING return false; } /** * @see org.jboss.cache.loader.CacheLoader#get(org.jboss.cache.Fqn) */ public Map<Object, Object> get(Fqn name) throws Exception { if (cache.getCacheStatus() == CacheStatus.STARTING) { // Before calling the nested cache loader we first check if the data exists in the local cache // in order to prevent multiple call to the cache store NodeSPI node = cache.peek(name, false); if (node != null) { // The node already exists in the local cache, so we return the corresponding data return node.getDataDirect(); } else { // The node doesn't exist in the local cache, so we need to check through the nested // cache loader return cl.get(name); } } // All the data is loaded at startup, so no need to call the nested cache loader for another // cache status other than CacheStatus.STARTING return null; } /** * @see org.jboss.cache.loader.CacheLoader#getChildrenNames(org.jboss.cache.Fqn) */ public Set<?> getChildrenNames(Fqn fqn) throws Exception { if (cache.getCacheStatus() == CacheStatus.STARTING) { // Try to get the list of children name from the nested cache loader return cl.getChildrenNames(fqn); } // All the data is loaded at startup, so no need to call the nested cache loader for another // cache status other than CacheStatus.STARTING return null; } ... {code} Se below the config {code:xml} <?xml version="1.0" encoding="UTF-8"?> <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1"> .. <loaders passivation="false" shared="true"> <!-- All the data of the JCR locks needs to be loaded at startup --> <preload> <node fqn="/" /> </preload> .. {code} -------------------------------------------------------------- To reply to this message visit the message page: http://community.jboss.org/message/525362#525362
_______________________________________________ jboss-user mailing list [email protected] https://lists.jboss.org/mailman/listinfo/jboss-user
