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

JavaScript to achieve accordion effect

This article shares the specific code for JavaScr...

Idea deploys remote Docker and configures the file

1. Modify the Linux server docker configuration f...

jQuery achieves large-screen scrolling playback effect

This article shares the specific code of jQuery t...

MySQL 5.7.18 installation tutorial and problem summary

MySQL 5.7.18 installation and problem summary. I ...

Explaining immutable values ​​in React

Table of contents What are immutable values? Why ...

How to export and import .sql files under Linux command

This article describes how to export and import ....

How to make a List in CocosCreator

CocosCreator version: 2.3.4 Cocos does not have a...

Solution to the error in compiling LVGL emulator on Linux

Table of contents 1. Error phenomenon 2. Error An...

In-depth discussion on auto-increment primary keys in MySQL

Table of contents Features Preservation strategy ...

Sample code for making desktop applications with vue + Electron

1.vue packaging Here we use the vue native packag...

Steps to create your own YUM repository

To put it simply, the IP of the virtual machine u...

Common naming rules for CSS classes and ids

Public name of the page: #wrapper - - The outer e...

Detailed explanation of three ways to set borders in HTML

Three ways to set borders in HTML border-width: 1...