Nginx Caching strategy

Maxim Dounin mdounin at mdounin.ru
Tue Oct 5 15:31:43 MSD 2010


Hello!

On Mon, Oct 04, 2010 at 03:12:57PM -0400, cachenewbie wrote:

> All -  Is there a high level tutorial on how nginx does caching ?  Does

Some information is available here (in Russian):

http://sysoev.ru/nginx/docs/http/ngx_http_proxy_module.html#proxy_cache_path

Translation is available here (looks like correct one, but I 
haven't really checked):

http://wiki.nginx.org/NginxHttpProxyModule#proxy_cache_path

> it use mmap to map the cache directory/file into memory and share it
> with all nginx worker processes (and use sendfile to send it out to the
> socket) ?  Or does it use directIO to open the file and use regular
> read/write syscalls ? This is for Linux debian platform.

nginx just saves responses to disk under the distinct names 
(derived from cache key), with headers at start.  When reading 
from cache, nginx uses regular read() (or aio if available and 
switched on) to read headers and normal file sending mecachnism to 
send body.

"Normal file sending mechanism" implies sendfile, aio, directio 
and so on - if available and configured.

Some metainformation about cache contents (to count cache 
accesses, remove old files and so on) are stored in shared memory.

Maxim Dounin



More information about the nginx mailing list