remotes: flush cached metadata when a remote's base_url changes #120

Merged
benvin merged 1 commits from benvin/flush-cache-on-remote-update into master 2026-08-13 08:29:25 +10:00
Member

Why

Switching a remote's backend (base_url) left artifactapi serving the previously-cached mutable metadata (repodata / Release / APKINDEX) until TTL expiry, so requests could keep pointing at the old upstream. cache.FlushRemote already existed but was wired to nothing.

How

  • Inject a MetadataFlusher (satisfied by *cache.Redis) into RemotesHandler via NewRemotesHandler; server.go passes s.cache.
  • On update, read the existing remote first, then after a successful DB update flush the remote's cached metadata when base_url changed, so the next request re-fetches fresh from the new upstream.
  • Keep scope to base_url (upstream identity); a flush failure is logged as a warning and does not fail the request since the DB update already landed.
  • Add tests: a base_url change flushes exactly once, an unchanged base_url does not flush, and a flush error still returns 200.
## Why Switching a remote's backend (`base_url`) left artifactapi serving the previously-cached mutable metadata (repodata / Release / APKINDEX) until TTL expiry, so requests could keep pointing at the old upstream. `cache.FlushRemote` already existed but was wired to nothing. ## How - Inject a `MetadataFlusher` (satisfied by `*cache.Redis`) into `RemotesHandler` via `NewRemotesHandler`; `server.go` passes `s.cache`. - On update, read the existing remote first, then after a successful DB update flush the remote's cached metadata when `base_url` changed, so the next request re-fetches fresh from the new upstream. - Keep scope to `base_url` (upstream identity); a flush failure is logged as a warning and does not fail the request since the DB update already landed. - Add tests: a `base_url` change flushes exactly once, an unchanged `base_url` does not flush, and a flush error still returns 200.
unkin-agent added 1 commit 2026-08-13 07:10:47 +10:00
remotes: flush cached metadata when a remote's base_url changes
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
e34c6570fc
Switching a remote's backend (base_url) left the previously-cached mutable
metadata (repodata / Release / APKINDEX) served until TTL expiry, pointing
at the old upstream. cache.FlushRemote existed but was wired to nothing.

- Inject a MetadataFlusher (satisfied by *cache.Redis) into RemotesHandler.
- On update, read the existing remote first, then after a successful DB
  update flush the remote's cached metadata when base_url changed so the
  next request re-fetches fresh from the new upstream.
- A flush failure is logged as a warning and does not fail the request; the
  DB update already landed.
- Add tests: base_url change flushes exactly once, an unchanged base_url
  does not flush, and a flush error still returns 200.
benvin merged commit 822f356881 into master 2026-08-13 08:29:25 +10:00
benvin deleted branch benvin/flush-cache-on-remote-update 2026-08-13 08:29:25 +10:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/artifactapi#120