Added the option to purge cache files directly without ngx_cache_purge #78
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue
I needed to be able to purge cache files without using the ngx_cache_purge module.
Solution
This pull request adds an option to the "Purge Options" area to allow the site admin to choose how cache files should be purged. The default option is to use a GET request to the /purge version of the URL, as required by ngx_cache_purge. The second option lets the plugin directly remove the cache files from the server.
Screenshot of new option:
How it works
I followed information from this article to compute the correct cache file to delete. The URL to delete is hashed with md5 and then given a specific folder and file name based on that hash.
Caveats
In order for the "delete local files" option to work, the following must all be true:
levels=1:2
fastcgi_cache_key "$scheme$request_method$host$request_uri"
Testing
So far it seems to work on my staging server tests. If someone else can help double check that everything is working great that would be much appreciated.