fix(memcache): refresh tag TTL when re-Setting an existing (key, tag)#307
Merged
Conversation
addKeyToTagValue returned early when the cache key was already in the tag's key list, skipping the CompareAndSwap that would have refreshed the tag's Expiration. This caused tag-based Invalidate to silently miss keys that were still being actively written, once the original tag TTL elapsed — diverging from the Redis store, which refreshes the tag TTL on every Set via an unconditional Expire after SAdd. Replace the manual loop + early return with slices.Contains: skip the duplicate append but always fall through to the CAS write so that Expiration is refreshed regardless of whether the list contents changed. Add a CompareAndSwap expectation to TestMemcacheSetWithTagsWhenAlreadyInserted so it acts as a regression test for this behavior. Fixes eko#305. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Fixes #305.
addKeyToTagValuereturned early when the cache key was already in the tag's key list, skipping theCompareAndSwapthat would have refreshed the tag'sExpiration. As a result, tag-basedInvalidatesilently missed keys that were still being actively written, once the original tag TTL elapsed — diverging from the Redis store, which refreshes the tag TTL on everySetvia an unconditionalExpireafterSAdd.Replaces the manual loop + early return with
slices.Contains: the duplicate append is still skipped, but the function now falls through to theCompareAndSwapsoExpirationis refreshed regardless of whether the list contents changed. The existingTestMemcacheSetWithTagsWhenAlreadyInsertedwas updated to expect theCompareAndSwapand now acts as a regression test for the behavior.