feat(storage): URL cache middleware (S06 Step 20)

What

S06 Storage Layer, Step 20 — Adjust URL Cache middleware.

Promotes the URL cache middleware out of internal/storage/_imported/ into its final home, internal/storage/middleware/urlcache/ — a storage.StorageDriver decorator that intercepts only URLFor.

Behavior

  • Cold call: fetch a pre-signed URL from the wrapped driver, return it, store it in Redis.
  • Warm call within the freshness window: serve the cached URL without calling the driver.
  • Near-expiry regeneration: driven by the Redis TTL (signed_url_expirymin_url_validity), so an entry self-evicts before its remaining lifetime crosses the min-validity floor.
  • dry_run: bypasses the cache entirely.
  • Redis read/write faults: degrade to a direct driver call rather than failing the request. A circuit breaker short-circuits cache access during a sustained Redis outage so requests stop paying the per-operation timeout.

Notes

  • signed_url_expiry is supplied by the composition root via Parameters.SignedURLExpiry (from the backend driver's config), since URLCacheConfig carries only min_url_validity and dry_run.
  • The constructor rejects a min_url_validity that is non-positive or >= signed_url_expiry (a cache that could never admit an entry) — approved.
  • URL-cache Prometheus metrics are not in this MR; the metric-framework prefix/registration is owned by #56 (closed), and the plan scopes Step 20's metric assertions to that follow-up.

Related to #165 (closed)

Edited by Pawel Rozlach

Merge request reports

Loading
Loading