jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1361551 - in /jmeter/trunk: src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java xdocs/usermanual/component_reference.xml
Date Sat, 14 Jul 2012 14:25:12 GMT
Author: pmouawad
Date: Sat Jul 14 14:25:11 2012
New Revision: 1361551

URL: http://svn.apache.org/viewvc?rev=1361551&view=rev
Log:
Bug 53522 - Cache Manager should not store at all response with header "no-cache" and store
other types of Cache-Control having max-age value
Changed to store entry forever if no max-age and no expires header which is what specification
says in my understanding:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Bugzilla Id: 53522

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java?rev=1361551&r1=1361550&r2=1361551&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
(original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
Sat Jul 14 14:25:11 2012
@@ -65,6 +65,8 @@ public class CacheManager extends Config
 
     private static final int DEFAULT_MAX_SIZE = 5000;
 
+    private static final long TWO_WEEKS_MS = 15*86400*1000;
+
     public CacheManager() {
         setProperty(new BooleanProperty(CLEAR, false));
         setProperty(new BooleanProperty(USE_EXPIRES, false));
@@ -160,16 +162,8 @@ public class CacheManager extends Config
         Date expiresDate = null; // i.e. not using Expires
         if (useExpires) {// Check that we are processing Expires/CacheControl
             final String MAX_AGE = "max-age=";
-            if(cacheControl != null) {
-                // if no-cache is present, ensure that expiresDate remains null, which forces
revalidation
-                if(cacheControl.contains(MAX_AGE) && ! cacheControl.contains("no-cache"))
{
-                    long maxAgeInSecs = Long.parseLong(
-                            cacheControl.substring(cacheControl.indexOf(MAX_AGE)+MAX_AGE.length())
-                                .split("[, ]")[0] // Bug 51932 - allow for optional trailing
attributes
-                            );
-                    expiresDate=new Date(System.currentTimeMillis()+maxAgeInSecs*1000);
-                }
-            } else if (expires != null) {
+            
+            if (expires != null) {
                 try {
                     expiresDate = DateUtil.parseDate(expires);
                 } catch (DateParseException e) {
@@ -179,6 +173,23 @@ public class CacheManager extends Config
                     expiresDate = new Date(0L); // invalid dates must be treated as expired
                 }
             }
+            // if no-cache is present, ensure that expiresDate remains null, which forces
revalidation
+            if(cacheControl != null && !cacheControl.contains("no-cache")) {    
+                // the max-age directive overrides the Expires header,
+                if(cacheControl.contains(MAX_AGE)) {
+                    long maxAgeInSecs = Long.parseLong(
+                            cacheControl.substring(cacheControl.indexOf(MAX_AGE)+MAX_AGE.length())
+                                .split("[, ]")[0] // Bug 51932 - allow for optional trailing
attributes
+                            );
+                    expiresDate=new Date(System.currentTimeMillis()+maxAgeInSecs*1000);
+                }   
+                // No max-age && No expires => store forever
+                else if(expires==null) {
+                    // No max-age
+                    expiresDate=new Date(System.currentTimeMillis()+TWO_WEEKS_MS);
+                }  
+                // else expiresDate computed in (expires!=null) condition is used
+            }
         }
         getCache().put(url, new CacheEntry(lastModified, expiresDate, etag));
     }

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1361551&r1=1361550&r2=1361551&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Jul 14 14:25:11 2012
@@ -3226,7 +3226,7 @@ Additionally, if the "Use Cache-Control/
 If the request is a GET request, and the timestamp is in the future, then the sampler returns
immediately,
 without requesting the URL from the remote server. This is intended to emulate browser behaviour.
 Note that if Cache-Control header is "no-cache", response will not be stored in cache, if
Cache-Control has any other value, 
-only the "max-age" expiry option is processed to compute entry lifetime.
+the "max-age" expiry option is processed to compute entry lifetime, if missing then expire
header will be used, if also missing entry will be cached forever (2 weeks).
 </p>
 <p>
 By default, Cache Manager will store up to 5000 items in cache using LRU algorithm. Use property
to modify this value.



Mime
View raw message