Maven Virtual Registry: Cache logic

🔭 Issues plan

  1. Maven Virtual Registry: Database models (#467972 - closed).
  2. Maven Virtual Registry: Permissions policy (#467977 - closed).
  3. Maven Virtual Registry: Registry models API (#467979 - closed).
  4. Maven Virtual Registry: Maven API endpoint (#467982 - closed).
  5. Maven Virtual Registry: Cache logic (#467983 - closed). 👈 You're here.
  6. Maven Registry: Cached responses destruction (#468113 - closed).
  7. Improve workhorse dependencyproxy logic (#461561 - closed).
  8. Maven Virtual Registry: Documentation (#468115 - closed).
  9. Maven Virtual Registry: Performance review (#468116 - closed).
  10. Maven Virtual Registry: feature flag cleanup (#468117).

🗒 Description

Cold cache or when the related cached response doesn't exist:

  • Use workhorse senddependency logic to return and upload the response from upstream.
    • At this time, record the ETag sent by upstream.
    • Set the upstream_etag_checked_at to now.
    • Set the downloaded_at to now.
    • Set the download_count to 1.

Warm cache or when the related cached response exist:

  • Check if now is within [upstream_etag_checked_at, upstream_etag_checked_at + cache_validity_period_hours].
    • If that's the case, use workhorse sendurl to send the cached_response.
      • Set the downloaded_at to now.
      • Set the download_count to +1.
    • If that's not the case, ping the related upstream to get the ETag header (HEAD request).
      • If the ETag is the same, use workhorse sendurl to send the cached_response.
        • Set the upstream_etag_checked_at to now.
        • Set the downloaded_at to now.
        • Set the download_count to +1.
      • If the ETag is not the same (stale cached response), destroy the cached_response and use workhorse senddependency logic to return and upload the response from upstream.
        • At this time, record the ETag sent by upstream.
        • Set the upstream_etag_checked_at to now.
        • Set the downloaded_at to now.
        • Set the download_count to download_count of the destroyed cached_response + 1. (the download_count carries over the cached response destruction.)
    • Special case: ETag header is missing from upstream. Execute the "ETag is not the same" branch.
Edited by David Fernandez