Author: markt
Date: Wed Oct 3 10:08:58 2012
New Revision: 1393385
URL: http://svn.apache.org/viewvc?rev=1393385&view=rev
Log:
Last of the caching configuration TODOs
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=1393385&r1=1393384&r2=1393385&view=diff
==============================================================================
---
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
(original)
+++
tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
Wed Oct 3 10:08:58 2012
@@ -258,6 +258,9 @@ public interface WebResourceRoot extends
void setCacheMaxSize(long cacheMaxSize);
long getCacheMaxSize();
+ void setCacheMaxObjectSize(long cacheMaxObjectSize);
+ long getCacheMaxObjectSize();
+
/**
* This method will be invoked by the context on a periodic basis and
allows
* the implementation a method that executes periodic tasks, such as
purging
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=1393385&r1=1393384&r2=1393385&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
Wed Oct 3 10:08:58 2012
@@ -4776,12 +4776,10 @@ public class StandardContext extends Con
resources.setCachingAllowed(isCachingAllowed());
resources.setCacheTtl(getCacheTTL());
resources.setCacheMaxSize(getCacheMaxSize());
+ resources.setCacheMaxObjectSize(getCacheObjectMaxSize());
resources.start();
- // TODO: Implement caching.
- // getCacheMaxObjectSize()
-
if (effectiveMajorVersion >=3 && addWebinfClassesResources) {
WebResource webinfClassesResource = resources.getResource(
"/WEB-INF/classes/META-INF/resources");
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=1393385&r1=1393384&r2=1393385&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
Wed Oct 3 10:08:58 2012
@@ -46,6 +46,7 @@ public class Cache {
private long ttl = 5000;
private long maxSize = 10 * 1024 * 1024;
+ private long maxObjectSize = maxSize / 20;
private ConcurrentMap<String,CachedResource> resourceCache =
new ConcurrentHashMap<>();
@@ -66,9 +67,13 @@ public class Cache {
}
if (cacheEntry == null) {
+ CachedResource newCacheEntry = new CachedResource(root, path, ttl);
+ if (newCacheEntry.getContentLength() > getMaxObjectSize()) {
+ return newCacheEntry;
+ }
+
// Concurrent callers will end up with the same CachedResource
// instance
- CachedResource newCacheEntry = new CachedResource(root, path, ttl);
cacheEntry = resourceCache.putIfAbsent(path, newCacheEntry);
if (cacheEntry == null) {
@@ -181,6 +186,15 @@ public class Cache {
this.maxSize = maxSize;
}
+
+ public void setMaxObjectSize(long maxObjectSize) {
+ this.maxObjectSize = maxObjectSize;
+ }
+
+ public long getMaxObjectSize() {
+ return maxObjectSize;
+ }
+
private static class EvictionOrder implements Comparator<CachedResource> {
@Override
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=1393385&r1=1393384&r2=1393385&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
Wed Oct 3 10:08:58 2012
@@ -331,6 +331,16 @@ public class StandardRoot extends Lifecy
}
@Override
+ public void setCacheMaxObjectSize(long cacheMaxObjectSize) {
+ cache.setMaxObjectSize(cacheMaxObjectSize);
+ }
+
+ @Override
+ public long getCacheMaxObjectSize() {
+ return cache.getMaxObjectSize();
+ }
+
+ @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=1393385&r1=1393384&r2=1393385&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
Wed Oct 3 10:08:58 2012
@@ -177,6 +177,16 @@ public class TesterWebResourceRoot imple
}
@Override
+ public void setCacheMaxObjectSize(long cacheMaxObjectSize) {
+ // NO-OP
+ }
+
+ @Override
+ public long getCacheMaxObjectSize() {
+ return 0;
+ }
+
+ @Override
public void addPreResources(WebResourceSet webResourceSet) {
// NO-OP
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]