Nginx memcache caching and invalidation

We currently use NGINX as our server, we use memcache to cache db queries as well as pages in php.

We have a version numbering system where in any update or insert happens this version number is bumped up, as a result memcache will always fetch new data as each key is appended with this version number. It works for us as read write % split is at 80/20 % so most of the times memcache is going to return the data without hitting the DB.

Now we plan to move this caching strategy to the server level where NGINX along with the memcache module will cache GET requests using the request uri along with the version number.

Just needed some feedback on how i can achieve this

  • Can i fetch this version number which is stored in memcache in NGINX? (this will be used to append it to the request uri)
  • How do i handle logged in users? (can I just set a cookie for a logged in user and check if this cookie exists in nginx if it does just pass the request to backend instead of memcache)

  • 1) unfortunately you can't do this with "vanila" nginx. but there are a couple of 3rd-party nginx modules witch can help you implement that. please take a look at

    Enhancement memcached protocol support https://github.com/bpaquet/ngx_http_enhanced_memcached_module http://wiki.nginx.org/NginxHttpMemcModule

    Value evaluation https://github.com/vkholodkov/nginx-eval-module

    I would like to recommend you give a chance to github.com/agentzh/ngx_openresty (nginx with many patches and modules) Great presentation about NGINX scripting agentzh.org/misc/slides/nginx-conf-scripting/nginx-conf-scripting.html

    2) There are a lot of examples over internet how disable caching for logging user

        if ($http_cookie ~* "auth_user") {
            # do some thing, set flag or so  
        }
    
    链接地址: http://www.djcxy.com/p/61676.html

    上一篇: magento开源全页面缓存

    下一篇: Nginx的memcache缓存和失效