refactor: remove global caches object#3167
Merged
Merged
Conversation
miparnisari
commented
Jun 9, 2026
| ) | ||
| ) | ||
|
|
||
| var caches sync.Map |
Contributor
Author
There was a problem hiding this comment.
The goal of this PR is to get rid of this global var.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
caches object
34e51cd to
3fbf9fe
Compare
miparnisari
commented
Jun 9, 2026
| // registration failure, already-registered metrics are rolled back. | ||
| func (wtc *otterCache[K, V]) registerMetrics(registerer prometheus.Registerer) error { | ||
| labels := prometheus.Labels{"cache": wtc.name} | ||
| collectors := []prometheus.Collector{ |
Contributor
Author
There was a problem hiding this comment.
i moved cache/metrics to here because i disliked the indirection. This does mean, though, that if we ever decide to add a new cache impl we will have to bring this too. I don't think we'll add a cache impl any time soon so that's why i did this
tstirrat15
approved these changes
Jun 9, 2026
Comment on lines
+69
to
+72
| name: name, | ||
| cache: cache, | ||
| metrics: otterMetrics{atomic.Uint64{}, counter}, | ||
| ttl: config.DefaultTTL, |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Solves #3156 (comment) by simplifying how our caching works.
Right now, each cache is registered in a global
caches sync.Map, which means that if you try to spin up 2 spicedb servers within the same process (as our tests do) and both have caching turned on, a panic will occur. This PR fixes that.