Skip to content

fix(memcache): refresh tag TTL when re-Setting an existing (key, tag)#307

Merged
eko merged 1 commit into
eko:masterfrom
semihbkgr:fix/memcache-tag-ttl-refresh
May 3, 2026
Merged

fix(memcache): refresh tag TTL when re-Setting an existing (key, tag)#307
eko merged 1 commit into
eko:masterfrom
semihbkgr:fix/memcache-tag-ttl-refresh

Conversation

@semihbkgr

Copy link
Copy Markdown
Contributor

Fixes #305.

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. As a result, tag-based Invalidate silently 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 every Set via an unconditional Expire after SAdd.

Replaces the manual loop + early return with slices.Contains: the duplicate append is still skipped, but the function now falls through to the CompareAndSwap so Expiration is refreshed regardless of whether the list contents changed. The existing TestMemcacheSetWithTagsWhenAlreadyInserted was updated to expect the CompareAndSwap and now acts as a regression test for the behavior.

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>

@eko eko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for this fix @semihbkgr

@eko eko merged commit f22c1c6 into eko:master May 3, 2026
10 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.

Memcache store does not refresh tag TTL when re-Setting an existing (key, tag), while Redis does

2 participants