changeset 1927:1f90fdd4fa04

Resolved TODO about caching certain WstValueTables. flys-artifacts/trunk@3307 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 23 Nov 2011 11:07:34 +0000
parents fde3db5e68e8
children 305a338c43c2
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java
diffstat 2 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Nov 22 20:04:46 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Nov 23 11:07:34 2011 +0000
@@ -1,3 +1,8 @@
+2011-11-23  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java:
+	  Resolved TODO about caching certain WstValueTables.
+
 2011-11-22  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java: New.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Tue Nov 22 20:04:46 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java	Wed Nov 23 11:07:34 2011 +0000
@@ -101,7 +101,7 @@
         loadQRanges(session, columns, wst_id);
         List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length);
 
-        WstValueTable valueTable =  new WstValueTable(columns, rows);
+        WstValueTable valueTable = new WstValueTable(columns, rows);
 
         if (valueTable != null && cacheKey != null) {
             log.debug("Store wst value table in cache");
@@ -117,7 +117,23 @@
      */
     public static WstValueTable getWstColumnTable(int wst_id, int col_pos) {
 
-        /** @TODO cached/uncached */
+        Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
+
+        WstValueTableCacheKey cacheKey;
+
+        if (cache != null) {
+            // A negaitve/negative number is the symbolic 'river-id' for
+            // "no river and kind but wst_id and colpos".
+            cacheKey = new WstValueTableCacheKey(-wst_id, -col_pos);
+            Element element = cache.get(cacheKey);
+            if (element != null) {
+                log.debug("Got specific wst value table from cache");
+                return (WstValueTable) element.getValue();
+            }
+        }
+        else {
+            cacheKey = null;
+        }
 
         Session session = SessionHolder.HOLDER.get();
 
@@ -127,7 +143,16 @@
         loadQRanges(session, columns, wst_id, col_pos);
         List<WstValueTable.Row> rows = loadRowsOneColumn(session, wst_id, col_pos);
 
-        return new WstValueTable(columns, rows);
+        WstValueTable valueTable = new WstValueTable(columns, rows);
+
+        if (valueTable != null && cacheKey != null) {
+            log.debug("Store wst value table in cache (wst: "
+                + wst_id + "/ col: " + col_pos + ")");
+            Element element = new Element(cacheKey, valueTable);
+            cache.put(element);
+        }
+
+        return valueTable;
     }
 
 

http://dive4elements.wald.intevation.org