summaryrefslogtreecommitdiff
path: root/installation/nginx-cache-purge.sh.example
blob: 5f6cbb128344b636006baf01c96d0bf567253a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 $@