# HG changeset patch # User Ingo Weinzierl # Date 1267086226 0 # Node ID f4331a0df032b18784df00f7480b242a1d4ae6d0 # Parent a72ecacccc91cfd81cbd2ca4d540152bbbd25d13 Chart and histogram output are working without using a cache. gnv-artifacts/trunk@710 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a72ecacccc91 -r f4331a0df032 gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Thu Feb 25 07:25:21 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Thu Feb 25 08:23:46 2010 +0000 @@ -13,6 +13,8 @@ import javax.xml.xpath.XPathConstants; +import net.sf.ehcache.Cache; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -190,22 +192,33 @@ */ protected Object getChartResult(String uuid, CallContext callContext) { log.debug("OutputStateBase.getChartResult"); - Object result = null; - if (CacheFactory.getInstance().isInitialized()) { - String key = "chart_" + getHash(); - log.debug("Hash for Queryelements: " + key); - net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); + CacheFactory factory = CacheFactory.getInstance(); + + if (factory.isInitialized()) { + // we use a cache + log.info("Using cache."); + Cache cache = factory.getCache(); + String key = "chart_" + getHash(); + + net.sf.ehcache.Element value = cache.get(key); if (value != null) { - result = value.getObjectValue(); - }else{ - result = this.getData(this.queryID); - if (CacheFactory.getInstance().isInitialized()) { - CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); - } - + log.debug("Found element in cache."); + return value.getObjectValue(); + } + else { + log.debug("Element not in cache, we need to ask the database"); + Object result = getData(queryID); + cache.put(new net.sf.ehcache.Element(key, result)); + + return result; } } - return result; + else { + // we don't use a cache, so we have to query the database every + // single time + log.info("Not using a cache."); + return getData(queryID); + } } protected Object getChartFromCache(String uuid, CallContext callContext) {