Mercurial > dive4elements > river
changeset 1898:7053e3255ab4
Employ cache for WstValueTables that have been fetched by wst_id.
flys-artifacts/trunk@3258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 16 Nov 2011 09:11:14 +0000 (2011-11-16) |
parents | cf8a376eb4c9 |
children | d002198c64a2 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java |
diffstat | 2 files changed, 32 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 <felix.wolfsteller@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java: + Cache WstValueTables that were fetched by wst_id. + 2011-11-16 Felix Wolfsteller <felix.wolfsteller@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.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<WstValueTable.Row> 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);