users@jersey.java.net

Re: [Jersey] Jersey and caching?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 03 Nov 2009 22:14:07 +0100

Hi Casper,

IIUC you want to utilize etags to save on server-side resources and
perhaps bandwidth? i.e. "deep" etags.

I am not an expert on using a proxy like squid for etag-based caching
but I think squid can work if resources are never updated, otherwise
one needs to communicate to squid to invalidate the cache. And you
will may require some etag processing on the web application if a PUT
or DELETE is performed.

So i think the choice of using EhCache is a good idea (IIRC Ruby on
Rails has integration with memcached).

I think the use of EhCache may need to work more closely with the
resources in question if updates can occur.

Note that you can use a Jersey filter, perhaps a resource, filter to
identify particular resources.

Off the top of my head...

public interface ETagable {
   public EntityTag getETag();
}

public class MyResource implements ETagable {

   public EntityTag getETag() { .... }

   ...
}

I am wondering if a resource filter could be applied to resources that
implement ETagable. The request resource filter could call getETag and
decide using EhCache whether to return a response e.g. a 304
(throwing an Exception that is mapped to a response) or letting the
resource method get called. A response resource filter may need to
invalidate the cache entry or update it.

Anyway i think this area is really an interesting one to experiment
with EhCache.

Paul.

On Nov 3, 2009, at 6:49 PM, Casper Bang wrote:

> Hello jersey list,
>
> Looking into adding caching to my Jersey resources (heavyweight chart
> generation) and was wondering about the approach. The classic REST
> approach seems to be embracing the HTTP protocol (etags and expire
> headers) and place something like Squid in front. Is the correct? I
> don't really have that option so I am looking into using EhCache and a
> servletfilter, interceping the URL and using it as a key to lookup a
> previous response. Does that sound like a good aproach? I have been
> searching for some documentation and blog entries regarding this, but
> found nothing. I did discover that apparently EhCache now has
> incorporated Jersey which might be what I need to look at.
>
> Any comments/links appreciated. Thanks,
> Casper
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>