Skip to content

cleanup: use oras-go content/cache for ORAS_CACHE - #2330

Merged
TerryHowe merged 1 commit into
oras-project:mainfrom
ShravanthReddy:cleanup/2313-use-oras-go-cache
Nov 24, 2026
Merged

TerryHowe merged 1 commit into
oras-project:mainfrom
ShravanthReddy:cleanup/2313-use-oras-go-cache

Conversation

@ShravanthReddy

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Builds on #2329. option.Cache.CachedTarget now delegates to oras-go's content/cache (cache.NewFromEnv() / (*Cache).ReadOnlyTarget()), and internal/cache/ is deleted (−440 / +81 lines, most of the additions being tests). The library reads ORAS_CACHE and stores content with the process-safe oci.NewStorage(), as #2329 does today.

Interface audit:

  • The library's CacheReadOnlyTarget keeps registry.ReferenceFetcher, ReferenceParser and ReferrerLister when the source has them. That's a superset of the old wrapper, which only kept ReferenceFetcher.
  • All four callers (pull, blob fetch, manifest fetch, manifest fetch-config) only pass the target to oras.Resolve / Fetch / FetchBytes / Copy and content.FetchAll, so no type assertion can regress.
  • The new test TestCache_CachedTarget_keepsReferenceFetcher asserts the interface through CachedTarget.

Behaviour change worth a look: FetchReference now resolves the tag with a HEAD first and serves cached content on a hit. That's one extra HEAD on a miss and no body download on a hit. The old wrapper always fetched references from the source. The new test pins this: the source's FetchReference is called once for two fetches.

Coverage: internal/cache/target_test.go had three tests. fetchCache and fetchReference are covered upstream (TestTarget_Fetch*, TestReferenceTarget_FetchReference*). pushPassThrough exercised an anonymous struct over memory.Store rather than the cache, so nothing is lost. #2329's tests are kept as they are.

Small doc note for oras-go, separately: Cache.ReadOnlyTarget's comment still says type assertions "may fail", but CacheReadOnlyTarget now keeps those interfaces.

go test -race ./... passes, golangci-lint is clean and go mod tidy leaves no diff.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2313. Happy to hand off or close if @Avadhut03 already has work in progress; fine to hold this until after the next CLI release.

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

oras-go v3 ships content/cache, which reads ORAS_CACHE, stores content
with the process-safe oci.NewStorage and keeps the source's
ReferenceFetcher, ReferenceParser and ReferrerLister interfaces.
internal/cache duplicated it and only kept ReferenceFetcher.

Reduce option.Cache.CachedTarget to a delegation and delete
internal/cache. Every caller (pull, blob fetch, manifest fetch,
manifest fetch-config) only passes the target to oras.Resolve/Fetch/
FetchBytes/Copy and content.FetchAll, so no interface assertion
regresses. A new test asserts the cached target still implements
registry.ReferenceFetcher.

Behaviour change: FetchReference now resolves the tag first and serves
cached content on a hit (one extra HEAD on a miss); the old wrapper
always fetched references from the source.

Fixes oras-project#2313

Signed-off-by: Shravanth Reddy <[email protected]>
@TerryHowe

Copy link
Copy Markdown
Member

Looks good. I'd like to deliver this after the next release though.

Comment thread cmd/oras/internal/option/cache.go Resolved

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.61%. Comparing base (02ffd9d) to head (8353782).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2330      +/-   ##
==========================================
+ Coverage   73.51%   73.61%   +0.09%     
==========================================
  Files         157      156       -1     
  Lines        6582     6519      -63     
==========================================
- Hits         4839     4799      -40     
+ Misses       1454     1440      -14     
+ Partials      289      280       -9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe
TerryHowe merged commit a12fcce into oras-project:main Nov 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cleanup: delete internal/cache in favor of oras-go/content/cache

2 participants