<div class="gmail_quote">Hi,<br><br>I work for a company which uses a lot the proxy module and the proxy cache feature.<br>We always have problems on clearing the cache because it has to be done url by url.<br><br>Thinking in a way to solve this I made the patch in attachment <br>
(nginx_cache_with_groups.patch, for nginx 1.0.10 and 0001-adding-parameter-to-purge-cache-by-groups.patch, for ngx_cache_purge 1.4).<br><br>Basically it changes the (fastcgi|proxy|scgi|uwsgi)_cache_key directives adding an optional value named "group key".<br>
This value accept any variable available on nginx configuration file (query parameters, headers,...) just like the key value.<br><br>When using this value a directory is created using the same structure of levels to store all files which have the same group key.<br>
Doing this we can purge the cache using a specific file, like is done today, or all files from a group. (I change the cache_purge_module to make this possible too)<br><br>I will give an example to be clear.<br>Imagine the configuration attached (nginx.conf) and that "html/static" folder has some files like test.css, test1.html and test2.html.<br>
With that configuration the extension file will be used as the group key and the uri as cache key.<br><br>When we execute the following commands the corresponded files are created:<br>command: curl -v '<a href="http://localhost:8090/test1.html" target="_blank">http://localhost:8090/test1.html</a>'<br>
file: ./e/53/a/fc35fdc70d5fc69d269883a822c7a53e/1/3d/9/bcccd499fbe303221add1b6e57d693d1 -> where fc35fdc70d5fc69d269883a822c7a53e is from group key and bcccd499fbe303221add1b6e57d693d1 from file key<br><br>command: curl -v '<a href="http://localhost:8090/test2.html" target="_blank">http://localhost:8090/test2.html</a>'<br>
file: ./e/53/a/fc35fdc70d5fc69d269883a822c7a53e/4/86/6/558156b89af1ccd4844556ab699d6864 -> where fc35fdc70d5fc69d269883a822c7a53e is from group key and 558156b89af1ccd4844556ab699d6864 from file key<br><br>command: curl -v '<a href="http://localhost:8090/test.css" target="_blank">http://localhost:8090/test.css</a>'<br>
file: ./a/66/2/c7a628cba22e28eb17b5f5c6ae2a266a/a/f0/d/9a96e0fe2f89d77e756fa45ae882df0a -> where c7a628cba22e28eb17b5f5c6ae2a266a is from group key and 9a96e0fe2f89d77e756fa45ae882df0a from file key<br><br>Now we can purge the cache from css file doing<br>
curl -v 'localhost:8090/purge/test.css' -H 'X-Group-Clean:0'<br><br>Or purge all html files doing<br>curl -v 'localhost:8090/purge/_.html' -H 'X-Group-Clean:1' (the underline in _.html is only to do a match on location)<br>
<br>The Group key can be as general or as specific like we want/need.<br>
<br>The default value for directive group_clean_cache_purge is 0, and the value used to it must be a text which converted to a number (ngx_atoi) results in a zero, purge only the selected file, or non zero, purge all files from selected group.<br>
<br><br>Another example of use is we have a service to resize images, and the desired size is passed through the uri like <br><a href="http://localhost/480x360/1361234.jpg" target="_blank">http://localhost/480x360/1361234.jpg</a> or <a href="http://localhost/x240/1361234.jpg" target="_blank">http://localhost/x240/1361234.jpg</a><br>
<br>With that patch we can group all resized images using the image id (1361234, in the example) as the group key and than purge all cached files at once.<br><br>I hope this patch can be applied in future versions of Nginx and made available to everyone.<br>
<br>Regards,<br>Wandenberg<br><br>
</div><br>