Python 定时清除缓存脚本
以下是一个 Python 脚本,可以定时清除缓存:
import os
import time
while True:
os.system('sync; echo 1 > /proc/sys/vm/drop_caches') # 清除缓存
print('Cache cleared at', time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
time.sleep(3600) # 每小时清除一次缓存
这个脚本会每隔一个小时清除一次缓存。如果想要更改时间间隔,可以修改time.sleep(3600)中的数字,单位是秒。
原文地址: https://www.cveoy.top/t/topic/mlvF 著作权归作者所有。请勿转载和采集!