diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2020-05-16 15:16:33 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2020-05-17 05:56:20 +0300 |
commit | 3f8d68bdf3224cd6023b3d7f8e64221222872820 (patch) | |
tree | 87262b9635af9bc869aae0be0e9bc57c4442db1d /installation | |
parent | cb40602a167f4637dc6df6633ec2dfe33f774177 (diff) | |
download | pleroma-3f8d68bdf3224cd6023b3d7f8e64221222872820.tar.gz pleroma-3f8d68bdf3224cd6023b3d7f8e64221222872820.zip |
added example cache purge script
Diffstat (limited to 'installation')
-rwxr-xr-x | installation/nginx-cache-purge.example | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/installation/nginx-cache-purge.example b/installation/nginx-cache-purge.example new file mode 100755 index 000000000..12dfa733c --- /dev/null +++ b/installation/nginx-cache-purge.example @@ -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 |