History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: CACHE-297
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Lars Torunski
Reporter: Brendan McNamara
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
OSCache

max-age parameter not set on ResponseContent object returned from cache when using MAX_AGE_NO_INIT

Created: 06/Jun/07 02:02 AM   Updated: 01/Jul/07 01:41 AM
Component/s: Filters
Affects Version/s: 2.4
Fix Version/s: 2.4.1

File Attachments: 1. Java Source File CacheHttpServletResponseWrapper.java (13 kb)

Issue Links:
Related
This issue relates to:
CACHE-278 Filter ignores max-age parameter when... Major Closed
This issue is related to:
CACHE-278 Filter ignores max-age parameter when... Major Closed

Flags: Patch


 Description  « Hide
I am getting the same problem that was reported in CACHE-278.
 
Issue CACHE-278 is reported as being closed but I am still getting the propblem after trying the 2.4 production release of oscache and have also tried versions; cache-2.4-20070519071202.jar and oscache-2.4.1-dev-20070519111245.jar from: http://ivyrep.opensymphony.com/opensymphony/oscache/.


I have the following configuration for the CacheFilter

<init-param>
<param-name>max-age</param-name>
<param-value>no init</param-value>
</init-param>

The first time I request a page from the cache I get the expected response (no max-age filter).

First Response:

HTTP/1.x 200 OK
Date: Wed, 06 Jun 2007 06:25:01 GMT
Content-Language: en-GB
Content-Type: application/xhtml+xml
Transfer-Encoding: chunked

On the second request when I recevie the cached response I get the following headers:

Second Response:

HTTP/1.x 200 OK
Date: Wed, 06 Jun 2007 06:25:22 GMT
Content-Language: en-GB
Content-Length: 11252
Content-Type: application/xhtml+xml
Cache-Control: max-age=60


I have traced the problem to the CacheHttpServletResponseWrapper class. In the constructor there is a block of code for setting up the max-age on the ResponseContent object that looks like this:

            // setting the cache control with max-age
            if (this.cacheControl == CacheFilter.MAX_AGE_TIME) {
             // set the count down
                long maxAge = System.currentTimeMillis();
                maxAge = maxAge - (maxAge % 1000) + time;
                result.setMaxAge(maxAge);
                super.addHeader(CacheFilter.HEADER_CACHE_CONTROL, "max-age=" + time / 1000);
            } else if (this.cacheControl != CacheFilter.MAX_AGE_NO_INIT) {
                result.setMaxAge(this.cacheControl);
                super.addHeader(CacheFilter.HEADER_CACHE_CONTROL, "max-age=" + (-this.cacheControl));
            }

The problem is that for the case when this.cacheControl == CacheFilter.MAX_AGE_NO_INIT you are not setting the value of the maxAge property on the ResponseContent (result) object. The ResponseContent object defaults maxAge to 60 so what happens is that when the response get's served from the cache instead of providing no value for max-age we get the default value of 60. For the first request the response does not get built from this ResponseContent object so that is why there was no max-age header.

The problem can be fixed by changing the block of code above to look like this:

// setting the cache control with max-age
            if (this.cacheControl == CacheFilter.MAX_AGE_TIME) {
             // set the count down
                long maxAge = System.currentTimeMillis();
                maxAge = maxAge - (maxAge % 1000) + time;
                result.setMaxAge(maxAge);
                super.addHeader(CacheFilter.HEADER_CACHE_CONTROL, "max-age=" + time / 1000);
            } else if (this.cacheControl != CacheFilter.MAX_AGE_NO_INIT) {
                result.setMaxAge(this.cacheControl);
                super.addHeader(CacheFilter.HEADER_CACHE_CONTROL, "max-age=" + (-this.cacheControl));
            } else if (this.cacheControl == CacheFilter.MAX_AGE_NO_INIT ) {
result.setMaxAge(this.cacheControl);
}

With the maxAge property set to equal CacheFilter.MAX_AGE_NO_INIT the ResponseContent object will not set the max-age header when the response gets served from the cache.









 All   Comments   Change History      Sort Order:
Brendan McNamara - [06/Jun/07 02:04 AM ]
Linking to issue CACHE-297 to issue CACHE-278

Brendan McNamara - [06/Jun/07 02:11 AM ]
Attatched updated version of CacheHttpServletResponseWrapper.java.

Lars Torunski - [09/Jun/07 02:34 AM ]
CacheHttpServletResponseWrapper fixed
Thanks to Brendan for the patch

Lars Torunski - [13/Jun/07 03:35 PM ]