Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 21901 invoked from network); 14 Nov 2006 04:17:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Nov 2006 04:17:51 -0000 Received: (qmail 37619 invoked by uid 500); 14 Nov 2006 04:18:01 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 37592 invoked by uid 500); 14 Nov 2006 04:18:01 -0000 Mailing-List: contact svn-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Forrest Developers List" List-Id: Delivered-To: mailing list svn@forrest.apache.org Received: (qmail 37581 invoked by uid 99); 14 Nov 2006 04:18:00 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Nov 2006 20:18:00 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Nov 2006 20:17:49 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 86FCF1A9846; Mon, 13 Nov 2006 20:17:19 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r474646 - in /forrest/trunk/main: java/org/apache/forrest/locationmap/LocationMapModule.java webapp/WEB-INF/xconf/forrest-core.xconf Date: Tue, 14 Nov 2006 04:17:19 -0000 To: svn@forrest.apache.org From: twilliams@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061114041719.86FCF1A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: twilliams Date: Mon Nov 13 20:17:18 2006 New Revision: 474646 URL: http://svn.apache.org/viewvc?view=rev&rev=474646 Log: Establish a simple TTL for the LM cache. Re: FOR-711 Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf Modified: forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java URL: http://svn.apache.org/viewvc/forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java?view=diff&rev=474646&r1=474645&r2=474646 ============================================================================== --- forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java (original) +++ forrest/trunk/main/java/org/apache/forrest/locationmap/LocationMapModule.java Mon Nov 13 20:17:18 2006 @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.Map; import java.util.HashMap; @@ -55,6 +56,8 @@ private SourceValidity m_srcVal; private LocationMap m_lm; private boolean m_cacheAll; + private int m_cacheTtl; + private Date m_cacheLastLoaded; private Map m_locationsCache; // ---------------------------------------------------- lifecycle @@ -70,9 +73,14 @@ public void configure(Configuration configuration) throws ConfigurationException { m_src = configuration.getChild("file").getAttribute("src"); m_cacheAll = configuration.getChild("cacheable").getValueAsBoolean(true); + m_cacheTtl = configuration.getChild("cache-lifespan").getValueAsInteger(); + + debug("LM Configured cache? " + m_cacheAll); + debug("LM Configured cache-lifespan: " + m_cacheTtl); if (m_cacheAll == true) { m_locationsCache = new HashMap(); + m_cacheLastLoaded = new Date(); } } @@ -121,6 +129,8 @@ m_resolver.release(source); } } + m_cacheLastLoaded = new Date(); + return m_lm; } @@ -168,6 +178,18 @@ try { if (this.m_cacheAll == true) { + Date now = new Date(); + long cacheAge = now.getTime() - m_cacheLastLoaded.getTime(); + debug("LM Cache current age is: " + cacheAge + "ms"); + + if (cacheAge > m_cacheTtl) { + debug("LM Cache has expiring - contains " + m_locationsCache.size() + " objects."); + synchronized (this) { + m_locationsCache.clear(); + debug("LM Cache has expired - now contains " + m_locationsCache.size() + " objects."); + } + } + hasBeenCached = m_locationsCache.containsKey(name); if (hasBeenCached == true) { result = m_locationsCache.get(name); @@ -226,4 +248,13 @@ return new Object[] {getAttribute(name,modeConf,objectModel)}; } + /** + * If debugging is turned on then log a debug message. + * @param debugString - the debug message + */ + private final void debug(String debugString) { + if (getLogger().isDebugEnabled()) { + getLogger().debug(debugString); + } + } } Modified: forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf URL: http://svn.apache.org/viewvc/forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf?view=diff&rev=474646&r1=474645&r2=474646 ============================================================================== --- forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf (original) +++ forrest/trunk/main/webapp/WEB-INF/xconf/forrest-core.xconf Mon Nov 13 20:17:18 2006 @@ -292,6 +292,7 @@ logger="core.modules.mapper.lm" name="lm"> true + 100000