“Ubuntu 缓存不生效”这个问题范围比较广,需要先明确你指的是哪一种缓存。下面我按常见场景分类说明,你可以对照看看是哪一种,以及可能原因和排查办法。
表现:
sudo apt install xxx 每次都重新下载,之前装过的 .deb 没被复用。
常见原因:
apt-get clean 或 apt clean 清掉了缓存--no-cache / -o Acquire::http::No-Cache=True排查:
ls -lh /var/cache/apt/archives/
cat /etc/apt/apt.conf.d/* | grep -i cache
解决:
apt clean表现:
修改了 /etc/hosts 或 DNS 后不生效,或解析很慢。
常见原因:
systemd-resolved 未启用dnsmasq 但配置错误排查:
systemctl status systemd-resolved
resolvectl status
解决:
sudo systemctl restart systemd-resolved
表现:
多次读文件速度没有变快。
常见原因:
direct I/Oecho 3 > /proc/sys/vm/drop_caches排查:
free -h
cat /proc/meminfo | grep Cache
表现:
配置了缓存但请求仍打到后端。
常见原因:
这通常不是“缓存不生效”,而是:
建议:
sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sudo apt update
为了更准确帮你,可以告诉我:
lsb_release -a)我可以直接帮你定位并给修复方案。