1 17 18 package org.sape.carbon.services.cache.mru; 19 20 import org.sape.carbon.core.component.ComponentConfiguration; 21 import org.sape.carbon.services.cache.CacheLoadException; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 34 public class DefaultMRUCacheImpl extends AbstractMRUCache { 35 36 protected MRUCacheDataLoader dataLoader; 37 38 39 private Log log = LogFactory.getLog(this.getClass()); 40 41 47 public void configure(ComponentConfiguration configuration) { 48 super.configure(configuration); 49 this.dataLoader = 50 ((MRUCacheConfiguration) configuration).getDataLoader(); 51 } 52 53 71 public Object get(Object key) { 72 Object value = getObject(key); 73 74 if (value == null) { 77 this.cacheMisses++; 78 79 try { 80 value = this.dataLoader.loadDatum(key); 81 82 if (log.isDebugEnabled()) { 86 log.debug("missed on cache: " + this.toString()); 87 } 88 89 synchronized (this) { 90 if (this.map.get(key) == null) { 94 put(key, value); 95 } 96 } 97 } catch (CacheLoadException cle) { 98 if (log.isWarnEnabled()) { 99 log.warn("Caught CacheLoadException loading datum " 100 + "with key [" 101 + key 102 + "], returning null: " 103 + cle); 104 } 105 } 106 } 107 108 return value; 111 } 112 } | Popular Tags |