nginx proxy_cache batch cache clearing script introduction

nginx proxy_cache batch cache clearing script introduction

Preface: I used the official nginx proxy_cache as CDN static cache before and found that it was a big problem to clear the cache in this module. It can only clear URLs one by one. For this reason, I wrote a script to clear the cache in batches.

Key features include:

1. Clean by file type

2. Clean up by specific file name

3. Clean up by website directory

The following is the bash shell script code. There are many similar scripts on the Internet before, but they are not very good and can easily mislead people to make mistakes.

#!/bin/bash
#Email:[email protected]
#Auto Clean Nginx Proxy_Cache Shell Scripts
#Aunthor:sun~shell
#Date:2017-02-23
echo -e "\n\n"
echo -n -e "\e[35;1mPlease enter the specific path of Nginx Proxy_cache cache (Friendly reminder: You can use the Tab completion function!)\e[0m\e[34;5m:\e[0m"
read -e path
CACHE_DIR=$path
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -n -e "\e[32;1mPlease enter the action you want to delete\n1. Delete by file type\t2. Delete by specific file name\t3. Delete by file directory\n:"
read action
   case $action in
1)
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -n -e "\e[34;1m Please enter the cache file type you want to delete (you can enter multiple parameters separated by spaces)\e[0m\e[34;5m:\e[0m"
read -a FILE
for i in `echo ${FILE[*]}|sed 's/ /\n/g'`
do
grep -r -a \.$i ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt
 for j in `cat /tmp/cache_list.txt`
do
  rm -rf $j
  echo "$i $j deleted successfully!"
 done
done
;;
2)
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -n -e "\e[33;1m Please enter the specific name of the cache file you want to delete (you can enter multiple parameters separated by spaces)\e[0m\e[34;5m:\e[0m"
read -a FILE
for i in `echo ${FILE[*]}|sed 's/ /\n/g'`
do
grep -r -a $i ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt
 for j in `cat /tmp/cache_list.txt`
do
  rm -rf $j
  echo "$i $j deleted successfully!"
 done
done
;;
3)
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -e "\e[32;1m----------------------------------------------------------------\e[0m"
echo -n -e "\e[33;1mSupported modes are:\n1. Clear all caches under the store directory of the website: test.dd.com/data/upload/shop/store\n2. Clear all caches under the shop directory of the website: test.dd.com/data/upload/shop\e[0m\n"
echo -n -e "\e[34;1m Please enter the specific directory of the cache file you want to delete\e[0m\e[34;5m:\e[0m"
read -a FILE
for i in `echo ${FILE[*]}|sed 's/ /\n/g'`
do
grep -r -a "$i" ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt
 for j in `cat /tmp/cache_list.txt`
do
  rm -rf $j
  echo "$i $j deleted successfully!"
 done
done
;;
*)
echo "Input error, please re-enter"
;;
esac

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • How to hide the version number and web page cache time in Nginx
  • Detailed explanation of setting resource cache in nginx
  • How to set up static files on the nginx cache server
  • How to handle Nginx and browser cache
  • Nginx cache configuration example

<<:  How to use VUE and Canvas to implement a Thunder Fighter typing game

>>:  Tutorial on using prepare, execute and deallocate statements in MySQL

Recommend

Common ways to optimize Docker image size

The Docker images we usually build are usually la...

...

About the "occupational disease" of designers

I always feel that designers are the most sensiti...

Summary of xhtml block level tags

* address - address * blockquote - block quote * c...

Why Use DOCTYPE HTML

You know that without it, the browser will use qui...

Use node-media-server to build a simple streaming media server

Record some of the processes of using node-media-...

5 Tips for Protecting Your MySQL Data Warehouse

Aggregating data from various sources allows the ...

Detailed explanation of the use of Linux time command

1. Command Introduction time is used to count the...

Detailed explanation of JavaScript axios installation and packaging case

1. Download the axios plugin cnpm install axios -...

We're driving IE6 to extinction on our own

In fact, we wonder every day when IE6 will really...

Detailed explanation of MySQL 8's new feature ROLE

What problems does MySQL ROLE solve? If you are a...

Solve the problem of garbled data in MySQL database migration

Under the instructions of my leader, I took over ...

Linux ssh server configuration code example

Use the following terminal command to install the...

JavaScript - Using slots in Vue: slot

Table of contents Using slots in Vue: slot Scoped...