Author: markt
Date: Thu Jul 3 14:30:21 2014
New Revision: 1607660
URL: http://svn.apache.org/r1607660
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56693
Fix various issues in the static resource cache implementation where the cache
retained a stale entry after the successful completion of an operation that
always invalidates the cache entry such as a delete operation.
Modified:
tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java
tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/webresources/Cache.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/Cache.java?rev=1607660&r1=1607659&r2=1607660&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/Cache.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/Cache.java Thu Jul 3
14:30:21 2014
@@ -76,7 +76,7 @@ public class Cache {
// Local copy to ensure consistency
int objectMaxSizeBytes = getObjectMaxSizeBytes();
CachedResource newCacheEntry =
- new CachedResource(root, path, getTtl(),
objectMaxSizeBytes);
+ new CachedResource(this, root, path, getTtl(),
objectMaxSizeBytes);
// Concurrent callers will end up with the same CachedResource
// instance
@@ -175,7 +175,7 @@ public class Cache {
return newSize;
}
- private void removeCacheEntry(String path) {
+ void removeCacheEntry(String path) {
// With concurrent calls for the same path, the entry is only removed
// once and the cache size is only updated (if required) once.
CachedResource cachedResource = resourceCache.remove(path);
Modified: tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java?rev=1607660&r1=1607659&r2=1607660&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/CachedResource.java Thu
Jul 3 14:30:21 2014
@@ -36,6 +36,7 @@ public class CachedResource implements W
// based on profiler data.
private static final long CACHE_ENTRY_SIZE = 500;
+ private final Cache cache;
private final StandardRoot root;
private final String webAppPath;
private final long ttl;
@@ -54,8 +55,9 @@ public class CachedResource implements W
private volatile Long cachedContentLength = null;
- public CachedResource(StandardRoot root, String path, long ttl,
+ public CachedResource(Cache cache, StandardRoot root, String path, long
ttl,
int objectMaxSizeBytes) {
+ this.cache = cache;
this.root = root;
this.webAppPath = path;
this.ttl = ttl;
@@ -180,7 +182,11 @@ public class CachedResource implements W
@Override
public boolean delete() {
- return webResource.delete();
+ boolean deleteResult = webResource.delete();
+ if (deleteResult) {
+ cache.removeCacheEntry(webAppPath);
+ }
+ return deleteResult;
}
@Override
Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1607660&r1=1607659&r2=1607660&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Thu
Jul 3 14:30:21 2014
@@ -164,7 +164,13 @@ public class StandardRoot extends Lifecy
return false;
}
- return main.mkdir(path);
+ boolean mkdirResult = main.mkdir(path);
+
+ if (mkdirResult && isCachingAllowed()) {
+ // Remove the entry from the cache so the new directory is visible
+ cache.removeCacheEntry(path);
+ }
+ return mkdirResult;
}
@Override
@@ -175,7 +181,14 @@ public class StandardRoot extends Lifecy
return false;
}
- return main.write(path, is, overwrite);
+ boolean writeResult = main.write(path, is, overwrite);
+
+ if (writeResult && isCachingAllowed()) {
+ // Remove the entry from the cache so the new resource is visible
+ cache.removeCacheEntry(path);
+ }
+
+ return writeResult;
}
private boolean preResourceExists(String path) {
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1607660&r1=1607659&r2=1607660&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jul 3 14:30:21 2014
@@ -100,6 +100,13 @@
domain, path, httpOnly and secure as were used to set the SSO cookie.
(markt)
</fix>
+ <fix>
+ <bug>56693</bug>: Fix various issues in the static resource cache
+ implementation where the cache retained a stale entry after the
+ successful completion of an operation that always invalidates the cache
+ entry such as a delete operation.
+ (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]