probably better to have cache control be an enum rather then boolean. -igor
On Sat, Sep 11, 2010 at 4:58 AM, <[email protected]> wrote: > Author: pete > Date: Sat Sep 11 11:58:49 2010 > New Revision: 996128 > > URL: http://svn.apache.org/viewvc?rev=996128&view=rev > Log: > give user control over [Cache-Control: public] or [Cache-Control:private] to > maximize caching or protect confidential or user-specific data from public > caching > > Modified: > > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/AbstractResource.java > > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/PackageResource.java > > Modified: > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/AbstractResource.java > URL: > http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/AbstractResource.java?rev=996128&r1=996127&r2=996128&view=diff > ============================================================================== > --- > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/AbstractResource.java > (original) > +++ > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/AbstractResource.java > Sat Sep 11 11:58:49 2010 > @@ -78,6 +78,7 @@ public abstract class AbstractResource i > private Date lastModified = null; > private WriteCallback writeCallback; > private int cacheDuration; > + private boolean cachePublic; > > /** > * Construct. > @@ -85,6 +86,11 @@ public abstract class AbstractResource i > public ResourceResponse() > { > cacheDuration = > Application.get().getResourceSettings().getDefaultCacheDuration(); > + > + // set caching on public caches to false. this > behavior is similar to wicket 1.4 > + // setting it to [true] seems to be sexy but could > potentially cache confidential > + // data on public proxies for users migrating to 1.5 > + cachePublic = false; > } > > /** > @@ -293,7 +299,7 @@ public abstract class AbstractResource i > /** > * Sets the duration for which this resource should be cached > on client (in seconds). #see > * {...@link IResourceSettings#setDefaultCacheDuration(int)} > - * > + * > * @param cacheDuration > * caching duration in seconds > */ > @@ -311,6 +317,37 @@ public abstract class AbstractResource i > } > > /** > + * returns if the resource may be cached by public caches or > not > + * <p/> > + * resources are only cached at all if the cache duration for > the response is > 0. > + * > + * @return <code>true</code> if public caches are allowed to > cache the resource > + * > + * @see > org.apache.wicket.request.resource.AbstractResource.ResourceResponse#getCacheDuration() > + * @see > org.apache.wicket.protocol.http.RequestUtils#enableCaching(org.apache.wicket.request.http.WebResponse, > int, boolean) > + */ > + public boolean isCachePublic() > + { > + return cachePublic; > + } > + > + /** > + * controls if the resource may be cached by public caches > + * <p/> > + * resources are only cached at all if the cache duration for > the response is > 0. > + * > + * @param cachePublic > + * if <code>true</code> public caches are allowed > to cache the resource > + * > + * @see > org.apache.wicket.request.resource.AbstractResource.ResourceResponse#getCacheDuration() > + * @see > org.apache.wicket.protocol.http.RequestUtils#enableCaching(org.apache.wicket.request.http.WebResponse, > int, boolean) > + */ > + public void setCachePublic(boolean cachePublic) > + { > + this.cachePublic = cachePublic; > + } > + > + /** > * Sets the {...@link WriteCallback}. The callback is > responsible for generating the response > * data. > * <p> > @@ -355,7 +392,7 @@ public abstract class AbstractResource i > > if(duration > 0) > { > - RequestUtils.enableCaching(response, duration, false); > + RequestUtils.enableCaching(response, duration, > data.isCachePublic()); > } > else > { > > Modified: > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/PackageResource.java > URL: > http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/PackageResource.java?rev=996128&r1=996127&r2=996128&view=diff > ============================================================================== > --- > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/PackageResource.java > (original) > +++ > wicket/trunk/wicket/src/main/java/org/apache/wicket/request/resource/PackageResource.java > Sat Sep 11 11:58:49 2010 > @@ -207,6 +207,14 @@ public class PackageResource extends Abs > return sendResourceError(resourceResponse, > 500, "Unable to open resource stream"); > } > } > + > + // if timestamps are enabled on resource we can maximize > caching with no pain > + > if(Application.get().getResourceSettings().getUseTimestampOnResources()) > + { > + > resourceResponse.setCacheDuration(RequestUtils.MAX_CACHE_DURATION); > + resourceResponse.setCachePublic(true); > + } > + > return resourceResponse; > } > > > >
