Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nginx-cache-purge
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@
SCRIPTNAME=${0##*/}

function print_usage() {
echo "$SCRIPTNAME <URI (grep pattern)> <cache directory>."
echo "$SCRIPTNAME <URI (grep pattern)> <cache directory> [number of parallel grep processes]"
}

## Check the number of arguments.
if [ $# -ne 2 ]; then
if [ $# -ne 2 ] && [ $# -ne 3 ]; then
print_usage
exit 1
fi

## Return the files where the items are cached.
## $1 - the filename, can be a pattern .
## $1 - the filename, can be a pattern.
## $2 - the cache directory.
## $3 - (optional) the number of parallel processes to run for grep.
function get_cache_files() {
Expand All @@ -56,13 +56,14 @@ function get_cache_files() {
} # get_cache_files

## Removes an item from the given cache zone.
## $1 - the filename, can be a pattern .
## $1 - the filename, can be a pattern.
## $2 - the cache directory.
## $3 - (optional) the number of parallel processes to run for grep.
function nginx_cache_purge_item() {
local cache_files

[ -d $2 ] || exit 2
cache_files=$(get_cache_files "$1" $2)
cache_files=$(get_cache_files "$1" $2 $3)

## Act based on grep result.
if [ -n "$cache_files" ]; then
Expand All @@ -79,4 +80,4 @@ function nginx_cache_purge_item() {
} # nginx_cache_purge_item

## Try to purge the given item from the cache.
nginx_cache_purge_item $1 $2
nginx_cache_purge_item $1 $2 $3