incubator-clerezza-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reto Bachmann-Gmuer <r...@apache.org>
Subject Client Side Caching
Date Sun, 04 Jul 2010 20:30:48 GMT
Hello

With this pathc by default clients are allowed to cache responses generated
from PathNodeS. During development and changed of static resources you may
either:

- press shift-reload to force reloading
- set a Cache-Control header withing the jax-rs resource returning the
PathNode (e.g. set Max-Age=0 if the resource is a file-uri)
- disable caching by configuring the component
org.apache.clerezza.web.fileserver.PathNodeWriter setting Max-Age to 0

note that with the latter two approach you might still need to press
shift-reload once for resources that have previously been cached.

Cheers,
reto

On Sun, Jul 4, 2010 at 8:56 PM, <reto@apache.org> wrote:

> Author: reto
> Date: Sun Jul  4 18:56:03 2010
> New Revision: 960384
>
> URL: http://svn.apache.org/viewvc?rev=960384&view=rev
> Log:
> CLEREZZA-255: adding cache-control if not there yet
>
> Modified:
>
>  incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.web.fileserver/src/main/java/org/apache/clerezza/web/fileserver/PathNodeWriter.java
>
> Modified:
> incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.web.fileserver/src/main/java/org/apache/clerezza/web/fileserver/PathNodeWriter.java
> URL:
> http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.web.fileserver/src/main/java/org/apache/clerezza/web/fileserver/PathNodeWriter.java?rev=960384&r1=960383&r2=960384&view=diff
>
> ==============================================================================
> ---
> incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.web.fileserver/src/main/java/org/apache/clerezza/web/fileserver/PathNodeWriter.java
> (original)
> +++
> incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.web.fileserver/src/main/java/org/apache/clerezza/web/fileserver/PathNodeWriter.java
> Sun Jul  4 18:56:03 2010
> @@ -32,19 +32,33 @@ import javax.ws.rs.ext.Provider;
>  import org.slf4j.Logger;
>  import org.slf4j.LoggerFactory;
>  import org.apache.clerezza.web.fileserver.util.MediaTypeGuesser;
> +import org.apache.felix.scr.annotations.Component;
> +import org.apache.felix.scr.annotations.Property;
> +import org.apache.felix.scr.annotations.Service;
> +import org.osgi.service.component.ComponentContext;
>  import org.wymiwyg.commons.util.dirbrowser.PathNode;
>
>  /**
>  *
>  * @author reto
> - *
> - * @scr.component
> - * @scr.service interface="java.lang.Object"
> - * @scr.property name="javax.ws.rs" type="Boolean" value="true"
>  */
> +@Component
> +@Service(value = Object.class)
> +@Property(name = "javax.ws.rs", boolValue = true)
>  @Provider
>  public class PathNodeWriter implements MessageBodyWriter<PathNode> {
> +
> +       @Property(value="600", description="Specifies the value of the
> max-age field"
> +               + "set in the cache-control header, as per RFC 2616 this is
> a number of "
> +               + "seconds")
> +       public static final String MAX_AGE = "max-age";
> +
>        private final Logger logger =
> LoggerFactory.getLogger(PathNodeWriter.class);
> +       private String cacheControlHeaderValue = "max-age:";
> +
> +       protected void activate(ComponentContext context) {
> +               cacheControlHeaderValue = "max-age="+(String)
> context.getProperties().get(MAX_AGE);
> +       }
>
>        @Override
>        public boolean isWriteable(Class<?> type, Type genericType,
> Annotation[] annotations, MediaType mediaType) {
> @@ -70,6 +84,11 @@ public class PathNodeWriter implements M
>                                logger.debug("Set media-type to: {}",
> guessedMediaType);
>                        }
>                }
> +               if (!httpHeaders.containsKey(HttpHeaders.CACHE_CONTROL)) {
> +                       httpHeaders.putSingle(HttpHeaders.CACHE_CONTROL,
> cacheControlHeaderValue);
> +               } else {
> +                       logger.debug("httpHeaders already contain
> CACHE_CONTROL");
> +               }
>                InputStream in = t.getInputStream();
>                for (int ch = in.read(); ch != -1; ch = in.read()) {
>                        entityStream.write(ch);
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message