aboutsummaryrefslogtreecommitdiff
path: root/installation/nginx-cache-purge.sh.example
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@pm.me>2020-05-28 12:07:30 +0300
committerRoman Chvanikov <chvanikoff@pm.me>2020-05-28 12:23:19 +0300
commitfddba6739de7e5f07f14338ccf5310a143a498cd (patch)
tree7c6b297ef53d5176059597ff4589bbbcce4afff2 /installation/nginx-cache-purge.sh.example
parent6cab0f820ec2ee112eb4dec84fa7d1c9cd9fca73 (diff)
parenta23df89b5d457ef56154069c132c75a590de810f (diff)
downloadpleroma-fddba6739de7e5f07f14338ccf5310a143a498cd.tar.gz
Merge develop
Diffstat (limited to 'installation/nginx-cache-purge.sh.example')
-rwxr-xr-xinstallation/nginx-cache-purge.sh.example40
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