# HG changeset patch # User Felix Wolfsteller # Date 1321434674 0 # Node ID 7053e3255ab4c78f8846029e32d90a680fd2f57d # Parent cf8a376eb4c9b9678bf8e8e3a5cb7301e5cdfbbc Employ cache for WstValueTables that have been fetched by wst_id. flys-artifacts/trunk@3258 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r cf8a376eb4c9 -r 7053e3255ab4 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Nov 16 09:10:07 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Nov 16 09:11:14 2011 +0000 @@ -1,3 +1,8 @@ +2011-11-16 Felix Wolfsteller + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java: + Cache WstValueTables that were fetched by wst_id. + 2011-11-16 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.java: diff -r cf8a376eb4c9 -r 7053e3255ab4 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 Wed Nov 16 09:10:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java Wed Nov 16 09:11:14 2011 +0000 @@ -62,7 +62,22 @@ */ public static WstValueTable getTable(int wst_id) { - /** @TODO cached/uncached */ + Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME); + + WstValueTableCacheKey cacheKey; + + if (cache != null) { + // "-1" is the symbolic river-id for "no river, but wst_id". + cacheKey = new WstValueTableCacheKey(-1, wst_id); + 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(); @@ -72,8 +87,18 @@ loadQRanges(session, columns, wst_id); List rows = loadRows(session, wst_id, columns.length); - return new WstValueTable(columns, rows); + WstValueTable valueTable = new WstValueTable(columns, rows); + + if (valueTable != null && cacheKey != null) { + log.debug("Store wst value table in cache"); + Element element = new Element(cacheKey, valueTable); + cache.put(element); + } + + return valueTable; } + + public static WstValueTable getTable(River river, int kind) { Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);