diff options
author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-05-20 20:27:03 +0300 |
---|---|---|
committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-05-20 20:27:03 +0300 |
commit | 6fd4f58ead9189697ed004b6ca593d5ba746898f (patch) | |
tree | 447bf02a1bc76941686e2017b6b8bed4494737d4 /installation/nginx-cache-purge.sh.example | |
parent | 1871a5ddb4a803ebe4fae6943a9b9c94f1f9c1a8 (diff) | |
parent | 265746b21f5a58f49efbdbe9d9eecd697781b93b (diff) | |
download | pleroma-6fd4f58ead9189697ed004b6ca593d5ba746898f.tar.gz pleroma-6fd4f58ead9189697ed004b6ca593d5ba746898f.zip |
Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
Diffstat (limited to 'installation/nginx-cache-purge.sh.example')
-rwxr-xr-x | installation/nginx-cache-purge.sh.example | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/installation/nginx-cache-purge.sh.example b/installation/nginx-cache-purge.sh.example new file mode 100755 index 000000000..b2915321c --- /dev/null +++ b/installation/nginx-cache-purge.sh.example @@ -0,0 +1,40 @@ +#!/bin/sh + +# A simple shell script to delete a media from the Nginx cache. + +SCRIPTNAME=${0##*/} + +# NGINX cache directory +CACHE_DIRECTORY="/tmp/pleroma-media-cache" + +## Return the files where the items are cached. +## $1 - the filename, can be a pattern . +## $2 - the cache directory. +## $3 - (optional) the number of parallel processes to run for grep. +get_cache_files() { + local max_parallel=${3-16} + find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -E Rl "^KEY:.*$1" | sort -u +} + +## Removes an item from the given cache zone. +## $1 - the filename, can be a pattern . +## $2 - the cache directory. +purge_item() { + for f in $(get_cache_files $1 $2); do + echo "found file: $f" + [ -f $f ] || continue + echo "Deleting $f from $2." + rm $f + done +} # purge_item + +purge() { + for url in "$@" + do + echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)" + purge_item $url $CACHE_DIRECTORY + done + +} + +purge $1 |