handling the ETag

Dmitri Zagidulin dzagidulin at basho.com
Thu Apr 25 13:52:29 EDT 2013

Hi Simon,

You are correct - setting the ETag in the Riak object header when doing a
PUT or POST does not work (there is no way to specify or change the ETag on
most riak clients).

The good news is, I think you can solve your particular problem (caching
users' web pages) without that capability. You don't really need the ETag
of the riak _object_ in which the page is stored to match the ETag of the
actual web page that the user's browser interacts with. (What etags are
actually used in Riak for, is with 'If-None-Match' or 'If-Modified-Since'
conditional HTTP semantics).

The easiest way to implement this caching behavior is - use the Etag of the
webpage as the key (or part of the key) for the riak object that stores the
web page. So:

1) The web page is generated, and sent to the user with an etag 'abcd'.
2) Store that web page in Riak using the etag as the key (here, 'abcd') or
as part of the key (something like 'your-url/index.html-abcd')
Ignore the fact that the etag in the riak object will be something
completely different, 'efgh'. You don't really need to use riak's etag.

3) When subsequent requests for that web page come in from the user's
browser, make a GET call to Riak for the etag 'abcd' and return it if it
exists, or else generate it & store it as usual.

(You're probably wondering about cache expiration, and how to clean up all
those stored web pages. Here, I would recommend using the Bitcask back end
and setting it to auto-expire (see the Automatic Expiration section of
http://docs.basho.com/riak/latest/tutorials/choosing-a-backend/Bitcask/ ).
The other alternative is to keep track of the web pages and their
expiration externally, and to issue explicit DELETE calls as part of a cron

Does that make sense?


On Wed, Apr 24, 2013 at 12:30 PM, Simon Majou <simon at majou.org> wrote:

> Hello,
> I am building a basic architecture : user / application server / riak. The
> web pages are generated on the application server, then sent to the user
> and finally stored (cached) in Riak. I would like the page sent to the user
> & the page stored in Riak to have the same ETag, so new requests with Etags
> are handled easily by forwarding them to Riak.
> I tried to set the ETag header when doing a PUT, but it doesn't have any
> effect.
> So how can I do that ? Obviously I don't want to store the page in Riak
> before sending it to the user as it would add latency.
> Simon
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20130425/c890faca/attachment.html>

More information about the riak-users mailing list