# HG changeset patch # User Felix Wolfsteller # Date 1322046454 0 # Node ID 1f90fdd4fa04d4239045c977b0fd661321820956 # Parent fde3db5e68e8d965163cc60434b8289cb20f3a93 Resolved TODO about caching certain WstValueTables. flys-artifacts/trunk@3307 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r fde3db5e68e8 -r 1f90fdd4fa04 flys-artifacts/ChangeLog --- 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 + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java: + Resolved TODO about caching certain WstValueTables. + 2011-11-22 Ingo Weinzierl * src/main/java/de/intevation/flys/artifacts/ExternalWMSArtifact.java: New. diff -r fde3db5e68e8 -r 1f90fdd4fa04 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java --- 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 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 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; }