logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

nginx-cache-purge.sh.example (957B)


  1. #!/bin/sh
  2. # A simple shell script to delete a media from the Nginx cache.
  3. SCRIPTNAME=${0##*/}
  4. # NGINX cache directory
  5. CACHE_DIRECTORY="/tmp/pleroma-media-cache"
  6. ## Return the files where the items are cached.
  7. ## $1 - the filename, can be a pattern .
  8. ## $2 - the cache directory.
  9. ## $3 - (optional) the number of parallel processes to run for grep.
  10. get_cache_files() {
  11. local max_parallel=${3-16}
  12. find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -E -Rl "^KEY:.*$1" | sort -u
  13. }
  14. ## Removes an item from the given cache zone.
  15. ## $1 - the filename, can be a pattern .
  16. ## $2 - the cache directory.
  17. purge_item() {
  18. for f in $(get_cache_files $1 $2); do
  19. echo "found file: $f"
  20. [ -f $f ] || continue
  21. echo "Deleting $f from $2."
  22. rm $f
  23. done
  24. } # purge_item
  25. purge() {
  26. for url in "$@"
  27. do
  28. echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)"
  29. purge_item $url $CACHE_DIRECTORY
  30. done
  31. }
  32. purge $@