You are viewing a plain text version of this content. The canonical link for it is here.
Posted to svn@forrest.apache.org by tw...@apache.org on 2006/11/14 05:17:19 UTC
svn commit: r474646 - in /forrest/trunk/main:
java/org/apache/forrest/locationmap/LocationMapModule.java
webapp/WEB-INF/xconf/forrest-core.xconf
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">
<file src="cocoon://locationmap.xml"/>
<cacheable>true</cacheable>
+ <cache-lifespan>100000</cache-lifespan>
</component-instance>
</input-modules>