how to disable / turn-off / refresh couchdb caching

冷暖自知 提交于 2020-01-13 19:18:30

问题


I have a list that has some basic authentication on a document. The issue I am having is that the list is caching so the user will not see they have access unless I update the revision id. How do you show a non-cached list?

if (req.userCtx.name === doc.permissions.owner) {
    return 'you have permission';   
}
else {
    return 'you do not';
}

How I would imagine it done is by passing no-cache or update the ETAG or something of that sort in the header, but nothing seems to work. Here is an attempt I have that sends a new date in the head every time to make it not cache, but this doesn't work.

var date = new Date().getTime() + 'x';
start({code: 200, headers: {'Content-Type': 'text/html', 'date': date}});

Any ideas greatly appreciated!

By the way I am looking for a pure couch solution.


回答1:


So after a lot more digging I found this:

http://wiki.apache.org/couchdb/Formatting_with_Show_and_List#ETags

Cutting to the important parts:

  • ETags are handled by the List and Shows
  • version up to 1.2 your user must have a role, then they will get different ETags.
  • 1.3 will introduce new ETags per user name.

Hope this helps someone.




回答2:


Fortunately CouchDB sources are available! I was able to find this algorithm in couch_mrview_show.erl:

show_etag(#httpd{user_ctx=UserCtx}=Req, Doc, DDoc, More) ->
    Accept = couch_httpd:header_value(Req, "Accept"),
    DocPart = case Doc of
        nil -> nil;
        Doc -> couch_httpd:doc_etag(Doc)
    end,
    couch_httpd:make_etag({couch_httpd:doc_etag(DDoc), DocPart, Accept,
        {UserCtx#user_ctx.name, UserCtx#user_ctx.roles}, More}).

Here we could see that Shows are cached unless one of the following things changed:

  • Design doc, which contain the show function
  • The doc which is used to render the show
  • 'Accept' HTTP request header
  • Username (it means that show is rendered at least once for each user)
  • Set of user roles in user context


来源:https://stackoverflow.com/questions/14947825/how-to-disable-turn-off-refresh-couchdb-caching

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!