changeset 2622:8bc1e1cb7f7b

Fixed the fixings columns caching problem. flys-artifacts/trunk@4207 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 06 Apr 2012 10:12:34 +0000
parents f0cc556eda29
children c4591312f3d3
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/cache.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverviewFactory.java
diffstat 4 files changed, 58 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Apr 05 18:25:48 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Apr 06 10:12:34 2012 +0000
@@ -1,3 +1,13 @@
+2012-04-06	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/conf/cache.xml: Increased number of fixings columns a bit.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java:
+	  Corrected misspelled cache name. Added bebug output.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FixingsOverviewFactory.java:
+	  Added debug output.
+
 2012-04-05	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java:
--- a/flys-artifacts/doc/conf/cache.xml	Thu Apr 05 18:25:48 2012 +0000
+++ b/flys-artifacts/doc/conf/cache.xml	Fri Apr 06 10:12:34 2012 +0000
@@ -106,7 +106,7 @@
 
     <!-- This one is used to hold the data columns of fixings. -->
     <cache name="fixings-columns"
-           maxElementsInMemory="50"
+           maxElementsInMemory="70"
            eternal="false"
            timeToLiveSeconds="7200"
            memoryStoreEvictionPolicy="LFU"
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java	Thu Apr 05 18:25:48 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java	Fri Apr 06 10:12:34 2012 +0000
@@ -16,9 +16,13 @@
 
 import org.hibernate.type.StandardBasicTypes;
 
+import org.apache.log4j.Logger;
+
 public class FixingsColumnFactory
 {
-    public static final String CACHE_NAME = "fixing-columns";
+    private static Logger log = Logger.getLogger(FixingsColumnFactory.class);
+
+    public static final String CACHE_NAME = "fixings-columns";
 
     public static final String SQL_COLUMN_WS =
         "SELECT wcv.position AS km, wcv.w AS w " +
@@ -41,27 +45,40 @@
 
     public FixingsColumn getColumnData(Fixing.Column column) {
 
-        FixingsColumn result;
+        boolean debug = log.isDebugEnabled();
+
+        if (debug) {
+            log.debug("FixingsColumnFactory.getColumnData");
+        }
 
         Cache cache = CacheFactory.getCache(CACHE_NAME);
 
-        if (cache != null) {
-            Integer cacheKey = Integer.valueOf(column.getId());
-            Element element = cache.get(cacheKey);
+        if (cache == null) {
+            if (debug) {
+                log.debug("Cache unconfigured.");
+            }
+            return getUncached(column);
+        }
 
-            if (element != null) {
-                return (FixingsColumn)element.getValue();
+        Integer cacheKey = Integer.valueOf(column.getId());
+        Element element  = cache.get(cacheKey);
+
+        if (element != null) {
+            if (debug) {
+                log.debug("Column " + cacheKey + " found in cache.");
             }
-
-            if ((result = getUncached(column)) != null) {
+            return (FixingsColumn)element.getValue();
+        }
+        else {
+            FixingsColumn result = getUncached(column);
+            if (result != null) {
+                if (debug) {
+                    log.debug("Store column " + cacheKey + " into cache.");
+                }
                 cache.put(new Element(cacheKey, result));
             }
+            return result;
         }
-        else {
-            result = getUncached(column);
-        }
-
-        return result;
     }
 
     protected FixingsColumn getUncached(Fixing.Column column) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverviewFactory.java	Thu Apr 05 18:25:48 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverviewFactory.java	Fri Apr 06 10:12:34 2012 +0000
@@ -23,11 +23,19 @@
 
     public static FixingsOverview getOverview(String river) {
 
-        log.debug("Looking for fixings overview for river '" + river + "'");
+        boolean debug = log.isDebugEnabled();
+
+        if (debug) {
+            log.debug(
+                "Looking for fixings overview for river '" + river + "'");
+        }
 
         Cache cache = CacheFactory.getCache(CACHE_NAME);
 
         if (cache == null) {
+            if (debug) {
+                log.debug("Cache not configured.");
+            }
             return getUncached(river);
         }
 
@@ -36,14 +44,19 @@
         Element element = cache.get(key);
 
         if (element != null) {
+            if (debug) {
+                log.debug("Overview found in cache");
+            }
             return (FixingsOverview)element.getValue();
         }
 
         FixingsOverview overview = getUncached(river);
 
         if (overview != null) {
-            element = new Element(key, overview);
-            cache.put(element);
+            if (debug) {
+                log.debug("Store overview in cache.");
+            }
+            cache.put(new Element(key, overview));
         }
 
         return overview;

http://dive4elements.wald.intevation.org