Skip to content

Conversation

@arthhhhh23
Copy link
Collaborator

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the SetIfAbsent method across all cache implementations in the codebase. The method sets a key-value pair only if the key doesn't already exist in the cache, returning the existing value (if present) and a boolean indicating whether the insertion was performed.

  • Adds SetIfAbsent to the Geche interface with proper documentation
  • Implements SetIfAbsent across all cache types (MapCache, MapTTLCache, RingBuffer, KVCache, KV) and wrapper types (Sharded, Updater, Locker)
  • Adds comprehensive test coverage including unit tests and panic tests for transaction handling

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
doc.go Adds SetIfAbsent method to the Geche interface with documentation
map.go Implements SetIfAbsent for MapCache using write lock and conditional insertion
map_ttl.go Implements SetIfAbsent for MapTTLCache with TTL support
ring.go Implements SetIfAbsent for RingBuffer, refactors Set method to extract internal set helper
kv_cache.go Implements SetIfAbsent for KVCache using existing get and insert helpers
kv.go Implements SetIfAbsent for KV wrapper using underlying cache
shard.go Implements SetIfAbsent for Sharded cache wrapper with proper shard routing
updater.go Implements SetIfAbsent for Updater wrapper by delegating to underlying cache
locker.go Implements SetIfAbsent for transaction Tx with panic guards for unlocked/read-only access
common_test.go Adds two generic test functions for SetIfAbsent behavior
kv_test.go Adds test for SetIfAbsent with multiple scenarios and updates MockErrCache
kv_cache_test.go Adds test for KVCache SetIfAbsent functionality
locker_test.go Adds panic tests for SetIfAbsent on read-locked and unlocked transactions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Owner

@C-Pro C-Pro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

}

c.data[key] = value
return old, true
Copy link

@judit-nugroho judit-nugroho Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use value instead bang Arthur?

Suggested change
return old, true
return value, true

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment in the inteface says:
// SetIfAbsent sets the kv only if the key didn't exist yet, and returns the existing value (if any) and whether the insertion was performed

We insert only when previous value did not exist, so old would be zero value in this case, which is consistent with other implementations.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaa isee, got it thanks bang Serger for the explanation

@arthhhhh23 arthhhhh23 merged commit 4997339 into C-Pro:main Dec 24, 2025
5 checks passed
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.

3 participants