Skip to content

[v17] Refactor cache to support storing resources in memory#54799

Merged
rosstimothy merged 1 commit intobranch/v17from
tross/backport-cache-collections/v17
Jun 25, 2025
Merged

[v17] Refactor cache to support storing resources in memory#54799
rosstimothy merged 1 commit intobranch/v17from
tross/backport-cache-collections/v17

Conversation

@rosstimothy
Copy link
Copy Markdown
Contributor

Backports #52210, #54637, and #54499 branch/v17

@rosstimothy rosstimothy added backport no-changelog Indicates that a PR does not require a changelog entry labels May 14, 2025
@rosstimothy rosstimothy force-pushed the tross/backport-cache-collections/v17 branch 5 times, most recently from 9ed462e to 1c8843e Compare May 15, 2025 12:04
@rosstimothy rosstimothy marked this pull request as ready for review May 15, 2025 12:38
@github-actions github-actions Bot requested a review from kiosion May 15, 2025 12:38
Base automatically changed from tross/backport-52414/v17 to branch/v17 May 16, 2025 14:44
@rosstimothy
Copy link
Copy Markdown
Contributor Author

Friendly ping @espadolini @fspmarshall. I believe that we're going to have our first attempt to backport a new cache collection to a release branch with #55807.

While the current cache storage is also in memory, it leverages
the memory backend which requires converting resources to and from
json. Marshaling json is suboptimal and is often a source of CPU
and memory consumption. The biggest problem with json marshaling
though is that it requires calling CheckAndSetDefaults. When
validations enforced in CASD become stricter it can leave caches
unable to become healthy when there are mixed versions within a
cluster as they all might have a slightly different view of what
should be allowed.

As a means to solve both problems, this changes the cache to store
resources received from the upstream directly in memory without
doing any conversion to json. There are two gotchas with this
approach, caching is no longer "free" and cloning of resources
must be done diligently to avoid races. Historically the cache
relied on the storage implementation in services/local to manage
persisting resources in the cache's backend.Memory. However, that
will no longer be the case as the cache needs to support storage
directly in memory. In order to reduce the burden this may pose on
developers the new collection machinery is simpler, and helpers
will be added on top of sortcache.SortCache to make a second
storage implementation trivial.

The changes here mark the existing collections machinery as legacy
and introduce new machinery to operate entirely in memory. The only
resources converted over are AccessRequests and HeadlessAuthentication.
@rosstimothy rosstimothy force-pushed the tross/backport-cache-collections/v17 branch from 1c8843e to b622f47 Compare June 25, 2025 13:23
@rosstimothy rosstimothy added this pull request to the merge queue Jun 25, 2025
Merged via the queue into branch/v17 with commit 2c9f9ee Jun 25, 2025
38 checks passed
@rosstimothy rosstimothy deleted the tross/backport-cache-collections/v17 branch June 25, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport no-changelog Indicates that a PR does not require a changelog entry size/lg

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants