added example cache purge script
This commit is contained in:
parent
cb40602a16
commit
3f8d68bdf3
5 changed files with 64 additions and 16 deletions
39
installation/nginx-cache-purge.example
Executable file
39
installation/nginx-cache-purge.example
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
|
||||
# A simple Bash script to delete an media from the Nginx cache.
|
||||
|
||||
SCRIPTNAME=${0##*/}
|
||||
|
||||
# NGINX cache directory
|
||||
CACHE_DIRECTORY="/tmp/pleroma-media-cache"
|
||||
|
||||
function get_cache_files() {
|
||||
local max_parallel=${3-16}
|
||||
find $2 -maxdepth 1 -type d | xargs -P $max_parallel -n 1 grep -ERl "^KEY:.*$1" | sort -u
|
||||
}
|
||||
|
||||
function purge_item() {
|
||||
local cache_files
|
||||
cache_files=$(get_cache_files "$1" "$2")
|
||||
|
||||
if [ -n "$cache_files" ]; then
|
||||
for i in $cache_files; do
|
||||
[ -f $i ] || continue
|
||||
echo "Deleting $i from $2."
|
||||
rm $i
|
||||
done
|
||||
else
|
||||
echo "$1 is not cached."
|
||||
fi
|
||||
}
|
||||
|
||||
function purge() {
|
||||
for url in "$@"
|
||||
do
|
||||
echo "$SCRIPTNAME delete $url from cache ($CACHE_DIRECTORY)"
|
||||
purge_item $url $CACHE_DIRECTORY
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
purge $1
|
||||
Loading…
Add table
Add a link
Reference in a new issue