feat(cache): add Memcached lock store#10154
Open
memleakd wants to merge 1 commit intocodeigniter4:4.8from
Open
feat(cache): add Memcached lock store#10154memleakd wants to merge 1 commit intocodeigniter4:4.8from
memleakd wants to merge 1 commit intocodeigniter4:4.8from
Conversation
- add CAS-backed Memcached lock store support - expose Memcached locks through MemcachedHandler - normalize unsupported runtime clients to LockException - cover owner-aware release, refresh, expiry, force release, and reconnect - document Memcached lock requirements and caveats Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.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.
Description
This PR follows up on the new Atomic Locks feature added in #10145 by adding Memcached as a supported lock store.
The initial locks PR intentionally shipped with File, Redis, and Predis support first because Memcached needed a more careful owner-aware design. This PR adds that missing store using the
memcachedPHP extension and CAS-based release/refresh behavior.Implementation
This adds:
CodeIgniter\Cache\LockStores\MemcachedLockStoreMemcachedHandler::lockStore()The implementation keeps the structure introduced in #10145:
*LockStoreclass.MemcachedHandleronly acts as aLockStoreProviderInterface.CodeIgniter\Lockcontinues to depend on cache lock-store contracts, not concrete cache handlers.Memcached Behavior
Lock acquisition uses Memcached's atomic
add()operation.Owner-aware
release()andrefresh()use CAS tokens fromMemcached::GET_EXTENDED. This avoids the unsafeget owner -> delete/touchpattern where a lock could expire and be reacquired by another owner between operations.Memcached does not provide an atomic compare-and-delete command, so release first uses CAS to shorten the TTL for the current owner before deleting the key. This keeps the owner check atomic while staying within Memcached's available operations.
The older
memcachePHP extension is not supported for locks because it does not provide the CAS operations needed for owner-aware release and refresh. IfMemcachedHandleris running withmemcache, resolving locks fails with the normal lock unsupported-store exception.Research Notes
This follows the same general direction as other ecosystems. Symfony provides a dedicated MemcachedStore in its Lock component [1], [2], and Laravel has a MemcachedLock implementation in its cache lock system.
For the Memcached-specific design, the important primitives are atomic
add()for acquisition and CAS tokens for owner-aware updates. PHP exposes CAS metadata throughMemcached::GET_EXTENDED, while Memcached’s protocol documentsadd/ CAS as the available race-safe storage primitives.Testing
Added live Memcached coverage for:
Checklist