feat: source caching#8291
Merged
Merged
Conversation
Introduces a shared SourceCache that deduplicates source executions across pipelines within a single updatecli run. Sources with identical Kind+Spec (after sanitization via ReportConfig) share a cache entry, regardless of Name, Transformers, or DependsOn differences. Refs: updatecli#8071 Signed-off-by: Loïs Postula <[email protected]>
Adds a cachingTransport that wraps the existing HTTP transport chain, caching successful GET responses in memory for the duration of one updatecli execution. This complements the source-level cache by deduplicating HTTP calls even when sources have different configs but query the same API endpoint. Refs: updatecli#8071 Signed-off-by: Loïs Postula <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Implements two in-memory caching layers to reduce redundant API calls and duplicate source executions during an updatecli run, addressing #8071 by caching HTTP GET responses centrally and deduplicating identical source executions across pipelines.
Changes:
- Add an opt-in HTTP response cache via a
cachingTransportinpkg/core/httpclient, toggled fromEngine.Run(). - Add a shared
SourceCachekeyed by a hash ofKind + sanitized Spec, injected fromEngineinto eachPipeline. - Update pipeline source execution to consult/populate the shared cache and add tests for both caching layers.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/core/pipeline/sources.go | Pass shared SourceCache into source execution. |
| pkg/core/pipeline/sources_test.go | Add pipeline-level cache miss/hit tests using a shared SourceCache. |
| pkg/core/pipeline/source/main.go | Implement source result caching (skip execution on hit; cache on successful miss). |
| pkg/core/pipeline/main.go | Add SourceCache field to Pipeline for engine injection. |
| pkg/core/httpclient/transport.go | Add global enable/disable hook to swap in caching transport for new clients. |
| pkg/core/httpclient/caching.go | New cachingTransport that caches successful GET responses in memory. |
| pkg/core/httpclient/caching_test.go | Add coverage for caching behavior, enable/disable toggling, and concurrency safety. |
| pkg/core/engine/run.go | Initialize/inject SourceCache and enable HTTP cache during engine execution. |
| pkg/core/engine/main.go | Add sourceCache field to Engine. |
| pkg/core/cache/source.go | New SourceCache implementation and keying via ReportConfig() hashing. |
| pkg/core/cache/source_test.go | Add unit tests for SourceCache and Key() behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Populate Status and ContentLength on cached HTTP responses - Reinitialize sourceCache on each Engine.Run() to prevent stale data - Fix DisableHTTPCache doc to accurately describe GC behavior Signed-off-by: Loïs Postula <[email protected]>
olblak
reviewed
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix #8071
Implements a two-layer in-memory caching system to reduce redundant API calls during pipeline execution, as proposed in #8071.
Layer 1: HTTP Response Cache (
pkg/core/httpclient/)A
cachingTransportwrapping the existing HTTP transport chain caches successful (2xx) GET responses in memory. All plugins benefit automatically since they go through the centralizedhttpclientpackage — zero plugin changes required.EnableHTTPCache()/DisableHTTPCache()inEngine.Run()sync.RWMutexLayer 2: Source Result Cache (
pkg/core/cache/)A
SourceCacheshared across pipelines deduplicates source executions when the same Kind+Spec appears in multiple pipelines (or multiple times within one). The cache key is a SHA256 of onlyKind+ sanitizedSpec(viaReportConfig()), so sources with the same plugin config but different names, transformers, ordependsOnshare a cache entry.Engineinto eachPipelinebefore executionHow they complement each other
Test
To test this pull request, you can run the following commands:
go test -race ./pkg/core/cache/ ./pkg/core/httpclient/ ./pkg/core/pipeline/ ./pkg/core/engine/Additional Information
Checklist
Tradeoff
cache.Key()function callsresource.New()to obtainReportConfig(), which means the plugin is instantiated twice on a cache miss (once for key, once for execution). This is acceptable for now as plugin constructors are lightweight.shellresource kind is cached like any other resource. For sources with side effects, this may need an opt-out mechanism in a future iteration — pending maintainer input.Potential improvement
singleflight.Groupto coalesce concurrent cache misses for the same key if pipeline execution is ever parallelized.nocache: true) per source for resources with side effects.resource.New()by threading the instantiated resource through the cache key computation.