http-enhanced-memc #
Drop-in replacement for the standard memcached module with custom HTTP header pass-through (Content-Type, Last-Modified) and flush/stats endpoints.
Source: upstream source
Directives
enhanced_memcached_allow_delete #
syntax: enhanced_memcached_allow_delete on | off (on/off flag); · context: location
Delete data in memcached === To delete entries in memcached, add a location in nginx config : location / { set $enhanced_memcached_key "$request_uri"; enhanced_memcached_allow_delete on; enhanced_memcached_pass memcached_upstream; } And send a DELETE HTTP request to this location.
enhanced_memcached_allow_put #
syntax: enhanced_memcached_allow_put on | off (on/off flag); · context: location
Store data into memcached === Add a location in nginx config like that: location / { set $enhanced_memcached_key "$request_uri"; enhanced_memcached_allow_put on; enhanced_memcached_pass memcached_upstream; } And send a PUT HTTP request into nginx, with body containing what you want to store in memcached, under the key $enhanced_memcached_key.
enhanced_memcached_bind #
syntax: enhanced_memcached_bind 1 arg; · context: http, server, location
Sets the local IP address for outgoing connections to the memcached upstream server.
enhanced_memcached_buffer_size #
syntax: enhanced_memcached_buffer_size 1 arg (size (k/m/g)); · context: http, server, location
Size in bytes; accepts k / m / g suffixes.
enhanced_memcached_connect_timeout #
syntax: enhanced_memcached_connect_timeout 1 arg (duration in ms); · context: http, server, location
Duration in milliseconds; accepts ms / s / m suffixes.
enhanced_memcached_flush #
syntax: enhanced_memcached_flush on | off (on/off flag); · context: location
Note : It can be used with enhanced_memcached_allow_put in the same location Flush memcached === To completely flush memcached, add a location in nginx config : location /flush { enhanced_memcached_flush on; enhanced_memcached_pass memcached_upstream; } And send a GET HTTP request on uri /flush.
enhanced_memcached_flush_namespace #
syntax: enhanced_memcached_flush_namespace on | off (on/off flag); · context: location
Boolean directive — set to "on" or "off".
enhanced_memcached_hash_keys_with_md5 #
syntax: enhanced_memcached_hash_keys_with_md5 on | off (on/off flag); · context: location
To use largest keys, just add in config : enhanced_memcached_hash_keys_with_md5 on; The enhanced memcached module will hash keys with md5 algorithm before inserting into memcached, and before getting data from memcached.
enhanced_memcached_pass #
syntax: enhanced_memcached_pass 1 arg; · context: location, location-if
Store data into memcached === Add a location in nginx config like that: location / { set $enhanced_memcached_key "$request_uri"; enhanced_memcached_allow_put on; enhanced_memcached_pass memcached_upstream; } And send a PUT HTTP request into nginx, with body containing what you want to store in memcached, under the key $enhanced_memcached_key.
enhanced_memcached_read_timeout #
syntax: enhanced_memcached_read_timeout 1 arg (duration in ms); · context: http, server, location
Duration in milliseconds; accepts ms / s / m suffixes.
enhanced_memcached_send_timeout #
syntax: enhanced_memcached_send_timeout 1 arg (duration in ms); · context: http, server, location
Duration in milliseconds; accepts ms / s / m suffixes.
enhanced_memcached_stats #
syntax: enhanced_memcached_stats on | off (on/off flag); · context: location
Stats memcached === To get memcached stats, add a location in nginx config : location /stats { enhanced_memcached_stats on; enhanced_memcached_pass memcached_upstream; } And send a GET HTTP request on uri /stats.
Example
worker_processes 1;
worker_rlimit_nofile 1000;
events {
worker_connections 1000;
}
pid nginx.pid;
error_log logs/error.log debug;
http {
default_type application/octet-stream;
upstream memcached_upstream {
server 127.0.0.1:11211;
keepalive 20;
}
server {
listen 127.0.0.1:8086;
server_name ~^(?<real_host>.*).put$;
location / {
set $enhanced_memcached_key "$request_uri";
set $enhanced_memcached_expire $http_memcached_expire;
set $enhanced_memcached_use_add $http_memcached_use_add;
set $enhanced_memcached_key_namespace "$real_host";
enhanced_memcached_hash_keys_with_md5 on;
enhanced_memcached_allow_put on;
enhanced_memcached_allow_delete on;
enhanced_memcached_pass memcached_upstream;
}
location /stats {
enhanced_memcached_stats on;
enhanced_memcached_pass memcached_upstream;
access_log off;
}
location /flushns {
set $enhanced_memcached_key "$request_uri";
set $enhanced_memcached_key_namespace "$real_host";
enhanced_memcached_flush_namespace on;
enhanced_memcached_pass memcached_upstream;
}
location /flush {
enhanced_memcached_flush on;
enhanced_memcached_pass memcached_upstream;
}
}
server {
listen 127.0.0.1:8086;
server_name ~^(?<real_host>.*)$;
gzip on;
gzip_proxied any;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/atom+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype;
gzip_vary on;
if ($request_method != GET) {
return 404;
}
if ($http_pragma ~* "no-cache") {
return 404;
}
if ($http_cache_control ~* "no-cache") {
return 404;
}
location / {
set $enhanced_memcached_key "$request_uri";
set $enhanced_memcached_key_namespace "$real_host";
enhanced_memcached_hash_keys_with_md5 on;
enhanced_memcached_pass memcached_upstream;
}
}
server {
listen 127.0.0.1:8087;
server_name ~^(?<real_host>.*).put$;
location / {
set $enhanced_memcached_key "$request_uri";
set $enhanced_memcached_expire $http_memcached_expire;
set $enhanced_memcached_use_add $http_memcached_use_add;
enhanced_memcached_hash_keys_with_md5 on;
enhanced_memcached_
…