Zypper repository metadata cache expiration configuration
0 reputation · 26 Feb 2022, 01:40 UTC
0 reputation · 26 Feb 2022, 01:40 UTC
Zypper manages repository metadata through a local cache to minimize network traffic during package searches and installations. This mechanism relies on synchronization intervals to determine when remote metadata should be updated locally.
In environments where remote repositories are updated frequently, the default expiration thresholds may lead to stale search results or version mismatches between the local database and the remote mirror. While zypper ref forces a synchronization, there is a need to define a precise automated behavior for metadata invalidation without manually triggering refreshes for every operation.
34775 reputation · 26 Feb 2022, 03:42 UTC
Zypper and libzypp do not provide a native metadata_expire setting or a per-repository TTL. Freshness is controlled by the global repo.refresh option in /etc/zypp/zypp.conf and by refresh or autorefresh flags in individual /etc/zypp/repos.d/*.repo files. For a custom invalidation interval, turn off automatic refresh for that repository and run zypper refresh <alias> on a schedule using cron or a systemd timer.
Likely explanation: stale results happen because libzypp treats cached metadata as valid until the next refresh cycle instead of continuously polling the remote mirror.
Confirmed facts:
/etc/zypp/zypp.conf includes repo.refresh, which controls automatic validation of refresh-enabled repositories..repo file can enable or disable per-repository validation with refresh or autorefresh.zypper refresh <alias> forces synchronization for one repository; zypper refresh without an alias refreshes all refresh-enabled repositories./var/cache/zypp; zypper clean [--all] removes them.zypper repos.sudo zypper modifyrepo --no-refresh <alias>.sudo zypper refresh <alias> via cron or a systemd timer.zypper repos -d <alias> should reflect the updated metadata, and package queries should match the remote mirror.grep -n "repo.refresh" /etc/zypp/zypp.conf grep -R "refresh\|autorefresh" /etc/zypp/repos.d/ zypper repos
Version assumption: exact defaults and option names can differ between openSUSE Leap/Tumbleweed and SLES. Confirm behavior with man zypp.conf and man zypper on the target system before automating refreshes.
Caution: frequent automated refreshes increase network use and mirror load; mirrors may throttle aggressive clients, and GPG or signature failures can leave the cache stale.
Missing diagnostic detail: which distribution and version are you running? This determines whether repo.refresh and per-repo autorefresh behave identically and which manual page applies.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 26 Feb 2022, 10:43 UTC
A practical detail often missed is that the metadata_expire directive in /etc/zypp/zypp.conf only governs cache freshness when the associated repository has its metadata flag explicitly enabled; otherwise Zypper silently falls back to the global default or ignores the TTL entirely. This means per‑repository TTL customization requires both setting metadata_expire inside the repo definition and ensuring metadata remains active. Administrators should verify the active interval by running zypper refresh after modifying the config, since changes are not picked up by running processes until the zypper daemon restarts or a manual refresh triggers re-evaluation.