added example cache purge script
[akkoma] / installation / nginx-cache-purge.example
1 #!/bin/bash
2
3 # A simple Bash script to delete an media from the Nginx cache.
4
5 SCRIPTNAME=${0##*/}
6
7 # NGINX cache directory
8 CACHE_DIRECTORY="/tmp/pleroma-media-cache"
9
10 function get_cache_files() {
11 local max_parallel=${3-16}
12 find $2 -maxdepth 1 -type d | xargs -P $max_parallel -n 1 grep -ERl "^KEY:.*$1" | sort -u
13 }
14
15 function purge_item() {
16 local cache_files
17 cache_files=$(get_cache_files "$1" "$2")
18
19 if [ -n "$cache_files" ]; then
20 for i in $cache_files; do
21 [ -f $i ] || continue
22 echo "Deleting $i from $2."
23 rm $i
24 done
25 else
26 echo "$1 is not cached."
27 fi
28 }
29
30 function purge() {
31 for url in "$@"
32 do
33 echo "$SCRIPTNAME delete $url from cache ($CACHE_DIRECTORY)"
34 purge_item $url $CACHE_DIRECTORY
35 done
36
37 }
38
39 purge $1