Skip to content

ValkeyCacheService: cluster support, bounded TTL, pre-built SetOptions - #528

Merged
stickfigure merged 1 commit into
objectify:masterfrom
frew:valkey-cache
Jul 12, 2026
Merged

stickfigure merged 1 commit into
objectify:masterfrom
frew:valkey-cache

Conversation

@frew

@frew frew commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Builds on the initial ValkeyCacheService (#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-built SetOptions: build the default SetOptions once instead of allocating a builder on every put/putAll, and add a constructor taking an explicit TTL.

Test coverage for these paths is added in ValkeyCacheServiceTests.

🤖 Generated with Claude Code

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.
@frew

frew commented Jul 8, 2026

Copy link
Copy Markdown
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.

@stickfigure
stickfigure merged commit 9909c0a into objectify:master Jul 12, 2026
@stickfigure

Copy link
Copy Markdown
Contributor

@frew sounds good, rolling it now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants