Nginx 全页缓存使用 Memcached/Elasticache 并使用 PHP 清除

Nginx full page cache using Memcached/Elasticache and purging with PHP

我在最新的 Nginx 上有一个 PHP 应用程序 运行。我想使用 memcached 为特定的 URL 缓存每个完整页面,并且还能够使用一些 PHP 命令 purge/invalidate 特定的缓存页面。

我的研究建议使用这两个模块:
http://wiki.nginx.org/HttpSRCacheModule
http://wiki.nginx.org/HttpMemcModule

这是best/easiest方式吗?还有其他建议吗?

你可以使用built-in Memcache module 配置很简单:

server {
    location / {
        set            $memcached_key "$uri?$args";
        memcached_pass host:11211;
        error_page     404 502 504 = @fallback;
    }

    location @fallback {
        proxy_pass     http://backend;
    }
}

缓存失效不是直截了当的,如果可能的话,使用短 TTL 强制缓存不显眼并按时间失效。否则寻找 Memcache 实践 here.