Skip to content

feat(conditionals): add put-if-absent + compare-and-set conditional writes - #20

Merged
uladkasach merged 1 commit into
mainfrom
vlad/feat-conditional-writes
Jul 22, 2026
Merged

uladkasach merged 1 commit into
mainfrom
vlad/feat-conditional-writes

Conversation

@ehm-a-seaturtle

Copy link
Copy Markdown
Contributor

feat(conditionals): add put-if-absent + compare-and-set conditional writes

implements WithCacheConditionals<SimpleCacheSync> so the cache can back
coordination primitives (mutex, stampede control, optimistic concurrency).

  • version(key): read the opaque, equality-only version token for a live key
  • get(key, { condition }): version-checked get — throws on a version mismatch
  • set(key, value, { condition }): put-if-absent (version: null) or
    compare-and-set (version: token); set(key, undefined, { condition }) is a
    compare-and-delete for safe mutex release
  • SimpleCacheConditionError (extends ConstraintError) thrown on a precondition miss
  • version tokens are uuids (via uuid-fns) — opaque, unorderable, stateless to mint
  • jest.serializer.uuid masks tokens to so snapshots stay deterministic

purely additive: every prior call compiles and behaves identically.
fulfills radio.task #19.


🐢🌊 surfed in by seaturtle[bot]

…rites

implements WithCacheConditionals<SimpleCacheSync<T>> so the cache can back
coordination primitives (mutex, stampede control, optimistic concurrency).

- version(key): read the opaque, equality-only version token for a live key
- get(key, { condition }): version-checked get — throws on a version mismatch
- set(key, value, { condition }): put-if-absent (version: null) or
  compare-and-set (version: token); set(key, undefined, { condition }) is a
  compare-and-delete for safe mutex release
- SimpleCacheConditionError (extends ConstraintError) thrown on a precondition miss
- version tokens are uuids (via uuid-fns) — opaque, unorderable, stateless to mint
- jest.serializer.uuid masks tokens to <uuid-N> so snapshots stay deterministic

purely additive: every prior call compiles and behaves identically.
fulfills radio.task #19.

Co-authored-by: Ulad Kasach <uladkasach@gmail.com>
@uladkasach
uladkasach merged commit 978376d into main Jul 22, 2026
16 checks passed
@uladkasach
uladkasach deleted the vlad/feat-conditional-writes branch July 22, 2026 01:12
@rhelease rhelease Bot mentioned this pull request Jul 22, 2026
@rhelease

rhelease Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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.

1 participant