Repository navigation
ValkeyCacheService: cluster support, bounded TTL, pre-built SetOptions - #528
Merged
Merged
Conversation
Builds on the initial ValkeyCacheService (PR objectify#527) with three changes: - Cluster-safe: hold the client as a BaseClient (standalone GlideClient or GlideClusterClient). Multi-key operations are issued as concurrent per-key commands instead of MGET/MSET/DEL, which would fail with CROSSSLOT on a cluster. CAS commands are routed to the primary owning the key's slot via SlotKeyRoute. - Bounded keyspace: every write carries a TTL, falling back to a configurable defaultExpirationSeconds (default 24h) when the entity declares no expiration. A noeviction cluster cannot shed cold entries via LRU the way memcache does, so unbounded writes would eventually exhaust maxmemory and fail all writers with OOM. Covers plain puts, the cold-cache null sentinel, and CAS writes with no explicit TTL. - Pre-build the default SetOptions once instead of allocating a builder on every put/putAll, and add a constructor taking an explicit TTL. Squashed from the StreakYC/objectify streak-valkey branch, excluding the fork's release-versioning and Artifact Registry publishing changes.
Contributor
Author
|
@stickfigure Rollout took a while, but here's all the changes we made productionizing it. The two big gotchas were: 1) valkey-glide uses a different concrete client class for cluster mode (which is what Memorystore runs) - made the library support both cluster and non-cluster (for easier local dev etc) and 2) the initial pass I forgot to specify a TTL so if the memory policy wasn't set to evict allkeys lru, you ran into a memory error - currently defaults to 24h TTL, but really doesn't matter much as long as it's something with a TTL so the default memory policy evicts on OOM. Happy to answer any questions/make any changes. Think it's ready for a publish if it all looks good to merge to you. |
Contributor
|
@frew sounds good, rolling it now. Thanks! |
This was referenced Jul 26, 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.
Builds on the initial
ValkeyCacheService(#527) with three changes:Cluster-safe: hold the client as a
BaseClient(standaloneGlideClientorGlideClusterClient). Multi-key operations are issued as concurrent per-key commands instead ofMGET/MSET/DEL, which would fail withCROSSSLOTon a cluster. CAS commands are routed to the primary owning the key's slot viaSlotKeyRoute.Bounded keyspace: every write carries a TTL, falling back to a configurable
defaultExpirationSeconds(default 24h) when the entity declares no expiration. Anoevictioncluster cannot shed cold entries via LRU the way memcache does, so unbounded writes would eventually exhaustmaxmemoryand fail all writers withOOM. Covers plain puts, the cold-cache null sentinel, and CAS writes with no explicit TTL.Pre-built
SetOptions: build the defaultSetOptionsonce instead of allocating a builder on everyput/putAll, and add a constructor taking an explicit TTL.Test coverage for these paths is added in
ValkeyCacheServiceTests.🤖 Generated with Claude Code