在 Debian 系统中,“禁用缓存”可能指软件包缓存、DNS 缓存、系统内存缓存或浏览器缓存等。下面分别说明常见场景及禁用方法。
.deb 包编辑 APT 配置文件:
sudo nano /etc/apt/apt.conf.d/99no-cache
添加以下内容:
Acquire::http::No-Cache "true";
Acquire::https::No-Cache "true";
或完全禁用包缓存:
Dir::Cache::archives "none";
sudo apt clean
sudo apt autoclean
如果系统使用 systemd-resolved:
systemctl status systemd-resolved
sudo systemd-resolve --flush-caches
编辑配置:
sudo nano /etc/systemd/resolved.conf
修改或添加:
Cache=no
重启服务:
sudo systemctl restart systemd-resolved
Linux 内核会自动使用内存作为缓存(page cache),不建议完全禁用,否则性能会严重下降。
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches
⚠️ 这不会“禁用”缓存,只是暂时清空。
sudo sysctl vm.vfs_cache_pressure=1000
about:configbrowser.cache.disk.enable → 设为 falsebrowser.cache.memory.enable → 设为 falseopcache.enable=0
add_header Cache-Control "no-store";
sudo swapoff -a
永久禁用(编辑 /etc/fstab,注释 swap 行)。
如果你能具体说明是 哪种缓存(例如:APT、DNS、内存、浏览器、Docker、APT 代理缓存等),我可以给你更精确的方案。