Author: markt
Date: Thu Sep 27 08:37:42 2012
New Revision: 1390889
URL: http://svn.apache.org/viewvc?rev=1390889&view=rev
Log:
Make cacher TTL configurable
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java?rev=1390889&r1=1390888&r2=1390889&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
Thu Sep 27 08:37:42 2012
@@ -238,6 +238,20 @@ public interface WebResourceRoot extends
*/
boolean getAllowLinking();
+ /**
+ * Set the Time-To-Live (TTL) for cache entries.
+ *
+ * @param ttl TTL in milliseconds
+ */
+ void setCacheTtl(long ttl);
+
+ /**
+ * Get the Time-To-Live (TTL) for cache entries.
+ *
+ * @return TTL in milliseconds
+ */
+ long getCacheTtl();
+
public static enum ResourceSetType {
PRE,
RESOURCE_JAR,
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java?rev=1390889&r1=1390888&r2=1390889&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
Thu Sep 27 08:37:42 2012
@@ -4786,10 +4786,11 @@ public class StandardContext extends Con
resources.setAllowLinking(isAllowLinking());
resources.start();
- // TODO: Implement caching. Is it necessary?
+ resources.setCacheTtl(getCacheTTL());
+ // TODO: Implement caching.
// isCachingAllowed()
- // getCacheTTL()
// getCacheMaxSize()
+ // getCacheMaxObjectSize()
if (effectiveMajorVersion >=3 && addWebinfClassesResources) {
WebResource webinfClassesResource = resources.getResource(
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java?rev=1390889&r1=1390888&r2=1390889&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/Cache.java
Thu Sep 27 08:37:42 2012
@@ -25,6 +25,8 @@ public class Cache {
private final StandardRoot root;
+ private long ttl = 5000;
+
private ConcurrentMap<String,CachedResource> resourceCache =
new ConcurrentHashMap<>();
@@ -36,7 +38,7 @@ public class Cache {
// Multiple concurrent callers will end up with the same CachedResource
// instance
// TODO Config for TTL
- CachedResource newCacheEntry = new CachedResource(root, path, 5000);
+ CachedResource newCacheEntry = new CachedResource(root, path, ttl);
CachedResource result =
resourceCache.putIfAbsent(path, newCacheEntry);
@@ -52,4 +54,14 @@ public class Cache {
}
// TODO add background expiration
+
+
+
+ public long getTtl() {
+ return ttl;
+ }
+
+ public void setTtl(long ttl) {
+ this.ttl = ttl;
+ }
}
Modified:
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java?rev=1390889&r1=1390888&r2=1390889&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
Thu Sep 27 08:37:42 2012
@@ -295,6 +295,14 @@ public class StandardRoot extends Lifecy
return allowLinking;
}
+ public long getCacheTtl() {
+ return cache.getTtl();
+ }
+
+ public void setCacheTtl(long cacheTtl) {
+ cache.setTtl(cacheTtl);
+ }
+
@Override
public Context getContext() {
return context;
Modified:
tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
URL:
http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java?rev=1390889&r1=1390888&r2=1390889&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
(original)
+++
tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
Thu Sep 27 08:37:42 2012
@@ -147,6 +147,16 @@ public class TesterWebResourceRoot imple
}
@Override
+ public void setCacheTtl(long ttl) {
+ // NO-OP
+ }
+
+ @Override
+ public long getCacheTtl() {
+ return 0;
+ }
+
+ @Override
public void addPreResources(WebResourceSet webResourceSet) {
// NO-OP
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]