Nginx – is anyway to use memcached with nginx on a post request

memcachednginx

2.1, i am also using the amazon elastic cache service (its a memcached server)

Nginx has a clever feature that uses memcached for common get request, but if is a post request dont use memcached, is anyway to disable this feature?

Here is my configuration;

location /{
    set_md5  $memcached_key "http://$server_name$uri";
    memcached_pass cacheviews.bsd7na.0001.use1.cache.amazonaws.com:11211;
    default_type text/html;
    add_header Content-Encoding gzip;
    error_page 405 404 = @fallback;
}

location @fallback{
    internal;
    gzip_types text/css text/plain application/atom+xml application/x-javascript;
    gzip_vary on;
    #  stuff to do a normal render of the page
}

Best Answer

When you get POST request, it is supposed to change some objects in your backend's storage (database), which depends on the logic of your application. So, NGINX just has no idea about what actually must be done in your application and simply does not try to cache any POST request, redirecting them directly to your backend.

Meanwhile, GET requests are supposed only to read data, without any writing - so, it can be easily cached, because every time the result of reading would be the same.