fastcgi_cache_path keys_zone=WPCACHE:2048m inactive=480m; disk size
I have setup a directive to cache to memdisk in nginx with:
fastcgi_cache_path /dev/shm/nginx levels=1:2 keys_zone=WPCACHE:2048m inactive=480m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
#snip other locations...
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php;
fastcgi_cache WPCACHE;
fastcgi_cache_valid 200 480m;
add_header X-Cache $upstream_cache_status;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
#more_clear_headers Server; more_clear_headers "Pragma";
add_header Z_LOCATION "PHP MAIN"; add_header URI $uri; # DEBUG
}
}
I understand this should limit size of cache to 2GB for 480 minutes, however it is now at 2.8GB so above this limit - any idea what I am doing wrong please?
root@www1:/dev/shm/nginx# du -sch *
182M 0
183M 1
177M 2
174M 3
177M 4
172M 5
172M 6
167M 7
174M 8
172M 9
168M a
171M b
174M c
177M d
172M e
179M f
2.8G total
The keys_zone
parameter of the fastcgi_cache_path
directive specifies a memory zone to store cache keys. Its size indirectly limits number of items the cache can store (1 megabyte ~ 8k items), but not on-disk size of the cache.
To limit on-disk size use the max_size
parameter:
fastcgi_cache_path ... max_size=2048m;
See fastcgi_cache_path documentation for more details.