org.apache.wicket.request.resource.caching
Class FilenameWithTimestampResourceCachingStrategy

java.lang.Object
  extended by org.apache.wicket.request.resource.caching.AbstractResourceCachingStrategy
      extended by org.apache.wicket.request.resource.caching.FilenameWithTimestampResourceCachingStrategy
All Implemented Interfaces:
IResourceCachingStrategy

public class FilenameWithTimestampResourceCachingStrategy
extends AbstractResourceCachingStrategy

resource caching strategy that adds a last-modified timestamp to the filename

timestamped_filename := [basename][timestamp-prefix][last-modified-milliseconds](.extension) Normally the resource names won't change when the resource ifself changes, for example when you add a new style to your CSS sheet. This can be very annoying as browsers (and proxies) usally cache resources in their cache based on the filename and therefore won't update. Unless you change the file name of the resource, force a reload or clear the browser's cache the page will still render with your old CSS.

Depending on HTTP response headers like 'Last-Modified' and 'Cache' automatic cache invalidation can take very, very long or neven happen at all.

Enabling timestamps on resources with this strategy will inject the last modification time of the resource into the filename (the name will look something like 'style-ts1282915831000.css' where the large number is the last modified date in milliseconds and '-ts' is a prefix to avoid conflicts with filenames that already contain a number before their extension. *

Since browsers and proxies use the filename of the resource as a cache key the changed filename will not hit the cache and the page gets rendered with the changed file.

Author:
Peter Ertl

Field Summary
protected static String DEFAULT_TIMESTAMP_SUFFIX
           
 
Fields inherited from class org.apache.wicket.request.resource.caching.AbstractResourceCachingStrategy
TIMESTAMP_KEY
 
Constructor Summary
FilenameWithTimestampResourceCachingStrategy()
          Constructor
FilenameWithTimestampResourceCachingStrategy(String timestampSuffix)
          Constructor
 
Method Summary
 void decorateResponse(AbstractResource.ResourceResponse response)
          set resource caching to maximum and set cache-visibility to 'public'
 void decorateUrl(ResourceUrl url, ResourceReference reference)
          add caching related information to filename + parameters
 String getTimestampPrefix()
           
 void undecorateUrl(ResourceUrl url)
          Removes caching related information from filename + parameters.
 
Methods inherited from class org.apache.wicket.request.resource.caching.AbstractResourceCachingStrategy
getLastModified, isLastModifiedCacheEnabled, setLastModifiedCacheEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TIMESTAMP_SUFFIX

protected static final String DEFAULT_TIMESTAMP_SUFFIX
See Also:
Constant Field Values
Constructor Detail

FilenameWithTimestampResourceCachingStrategy

public FilenameWithTimestampResourceCachingStrategy()
Constructor


FilenameWithTimestampResourceCachingStrategy

public FilenameWithTimestampResourceCachingStrategy(String timestampSuffix)
Constructor

Parameters:
timestampSuffix - string appended to the filename before the timestamp
Method Detail

getTimestampPrefix

public final String getTimestampPrefix()
Returns:
string appended to the filename before the timestamp

decorateUrl

public void decorateUrl(ResourceUrl url,
                        ResourceReference reference)
Description copied from interface: IResourceCachingStrategy
add caching related information to filename + parameters

Parameters:
url - parameters to which caching information should be added and which will be used to construct the url to the resource
reference - resource reference

undecorateUrl

public void undecorateUrl(ResourceUrl url)
Description copied from interface: IResourceCachingStrategy
Removes caching related information from filename + parameters. In essenese this method undoes what IResourceCachingStrategy.decorateUrl(ResourceUrl, ResourceReference) did.

Parameters:
url - parameters that were used to construct the url to the resource and from which previously added caching information should be stripped

decorateResponse

public void decorateResponse(AbstractResource.ResourceResponse response)
set resource caching to maximum and set cache-visibility to 'public'

Parameters:
response -


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.