Understanding fastcgi_cache_path, levels, keys_zone, max_size, inactive, use_temp_path

A note for myself to exaplain fastcgi_cache_path, levels, keys_zone, max_size, inactive, use_temp_path

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WPCACHE:100M max_size=10G inactive=1d use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;

As documentation said, nginx will keep all active keys and information about data are stored in a shared memory zone, whose name and size are configured by the keys_zone parameter. As a matter of completeness, lets break down per part

  • /var/cache/nginx is the place where the actual cache stored. Inside the folder, cache file was binary file but you can easily spot the html tag inside it.
  • levels=1:2 is levels parameter sets the number of subdirectory levels in cache.
  • keys_zone=WPCache:100m was defining shared memory zone named WPCache with maximum size 100 MB. It holds all active keys and metadata of the cache. So, whenever nginx checks if a page was cached, it consults the shared memory zone first, then seek the location of actual cache in /var/cache/nginx if cache exist.
  • max_size was maximum size of cache e.g. files size on /var/cache/nginx.
  • inactive=1d specify maximum inactive time cache can be stored. Cached data that are not accessed during the time specified by the inactive parameter get removed from the cache regardless of their freshness.
  • use_temp_path turn off the temp path, if not it will use /usr/local/nginx/fastcgi_temp


Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.