1. CouchDB
  2. COUCHDB-1422

Let _show/_list functions prevent caching


    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:


      While CouchDB's automatic ETag handling on Show/List functions is desirable 95% of the time, I keep running into situations where I want to do something handy in a documentless show function ("if all you have is a hammer...") but end up getting into trouble with cached responses.

      I think the most straightforward fix is to send along any ETag header in a viewserver response instead of the default. Currently, instead of overriding the ETag header, the two headers are combined. This does "bust the cache" in some browsers if the only attempt to revalidate the first one (which happens to be that of the show function), but Firefox at least sends both back and CouchDB finds its match and responds with 304 "Not Modified". Letting a show/list function return a single garbage ETag would let it avoid having its result considered so strongly valid later.

      Consider my stupid simple little public IP address reflector ( or the following show:

      function (doc, req)

      { return "Now is " + Date() + " and here is a unique identifier " + req.uuid + " which might have more entropy than " + Math.random(); }

      There are a lot of interesting/fun things that are well within JavaScript's reach in a (practically) side-effect free formatting function: different stylesheet based on user agent, SVG chart of DB stats in, random quote generator... None of these are practical if the response will quickly end up locked by a cache — potentially in proxies well upstream of the client — based on an overly narrow definition (and IMO sometimes needless requirement) of idempotence.

      Letting the show function "bust the cache" by providing a response ETag which CouchDB won't re-validate would be a simple way to avoid this. With my proposal above, my IP address example would simply override the ETag and avoid 304-effects altogether:

      function (doc, req) {
      return {headers:


      , body: "Your IP address is: " + req.peer};

      [If such a function wanted to allow for some caching benefit, it could provide an appropriate Expires header instead.]


        No work has yet been logged on this issue.


          • Assignee:
            Robert Newson
            Nathan Vander Wilt
          • Votes:
            0 Vote for this issue
            1 Start watching this issue


            • Created: