在 Debian 系统中,“缓存”通常涉及 APT 软件包缓存、系统内存缓存(如 Page Cache) 以及 代理或应用层缓存。最常用的场景是 开启或优化 APT 的包缓存 和 磁盘缓存相关设置。下面分情况说明。
Debian 默认 已经开启 APT 缓存,无需手动启用,但你可以优化配置。
.deb 包会保存在:/var/cache/apt/archives/
du -sh /var/cache/apt/archives
sudo apt clean # 删除所有已下载的包
sudo apt autoclean # 仅删除过期的包(推荐)
编辑 APT 配置:
sudo nano /etc/apt/apt.conf.d/99cache
示例配置(限制缓存为 500MB):
Acquire::Max-Future-Keep "30";
Dir::Cache::archives "cachedir";
或者限制缓存过期时间:
APT::Clean-Installed "false";
适合 多台 Debian 机器共用缓存 的场景。
sudo apt install apt-cacher-ng
sudo systemctl enable apt-cacher-ng
sudo systemctl start apt-cacher-ng
在其它 Debian 机器的 /etc/apt/apt.conf.d/99proxy 中:
Acquire::http::Proxy "http://缓存服务器IP:3142";
✅ 这样所有软件包下载都会被缓存
Debian 默认 已开启 Linux 内核缓存,一般不需要手动干预。
free -h
buff/cache 即为缓存sync
sudo sysctl vm.drop_caches=3
⚠️ 不建议长期禁用或频繁清理
Debian 默认没有 DNS 缓存(systemd-resolved 除外)。
sudo apt install dnsmasq
sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq
| 应用 | 缓存位置 |
|---|---|
| Firefox | ~/.cache/mozilla/ |
| Chrome | ~/.cache/google-chrome/ |
| Docker | /var/lib/docker/tmp/ |
| 需求 | 是否已开启 |
|---|---|
| APT 包缓存 | ✅ 默认开启 |
| 系统内存缓存 | ✅ Linux 自动 |
| apt-cacher-ng | ❌ 需手动安装 |
| DNS 缓存 | ❌ 需安装 |
如果你能具体说明是 APT 缓存 / 系统缓存 / 局域网缓存 / Docker 缓存 / 代理缓存,我可以给你更精确的一步到位方案。