Skip to content

refactor: abstract versioned cache#483

Merged
talos-bot merged 1 commit into
siderolabs:mainfrom
Orzelius:versioned-cache
Jun 15, 2026
Merged

refactor: abstract versioned cache#483
talos-bot merged 1 commit into
siderolabs:mainfrom
Orzelius:versioned-cache

Conversation

@Orzelius

Copy link
Copy Markdown
Member

I didn't wan't to duplicate the code a fourth time for the extra extensions so here's a little abstraction

@github-project-automation github-project-automation Bot moved this to To Do in Planning Jun 12, 2026
@talos-bot talos-bot moved this from To Do to In Review in Planning Jun 12, 2026
@Orzelius Orzelius force-pushed the versioned-cache branch 2 times, most recently from 80d5d80 to 535de54 Compare June 12, 2026 15:01
@shanduur shanduur self-requested a review June 12, 2026 19:55
Comment thread internal/cache/versioned.go Outdated
// Failed fetches are not cached.
type VersionedCache[T any] struct {
fetch func(tag string) ([]T, error)
entries map[string][]T

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.

in order to make it more generic, I would replace []T here with T, as nothing in this code relies on it being a slice actually.

On error, return zero value of T (var zero T) instead of nil.

This would make this code work with any T type.

Comment thread internal/cache/versioned.go Outdated
// Fetches are de-duplicated across concurrent callers via an internal
// singleflight group, and respect the caller's context for cancellation.
// Failed fetches are not cached.
type VersionedCache[T any] struct {

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.

Probably something like SingleflightCache (as it's not really versioned in any way). It's rather unbounded cache with singleflight protection?

Comment thread internal/cache/single_flight.go Outdated
Comment thread internal/cache/single_flight_test.go Outdated
Comment thread internal/cache/single_flight_test.go Outdated
Comment thread internal/cache/single_flight_test.go Outdated
@github-project-automation github-project-automation Bot moved this from In Review to Approved in Planning Jun 15, 2026
I didn't wan't to duplicate the code a fourth time for the extra extensions so here's a little abstraction

Signed-off-by: Orzelius <33936483+Orzelius@users.noreply.github.com>
@Orzelius

Copy link
Copy Markdown
Member Author

/m

@talos-bot talos-bot merged commit e0e4a44 into siderolabs:main Jun 15, 2026
29 of 30 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Done in Planning Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants