Skip to content

[13.x] Implement CanFlushLocks on FailoverStore#59738

Open
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
sumaiazaman:feat/failover-store-flush-locks
Open

[13.x] Implement CanFlushLocks on FailoverStore#59738
sumaiazaman wants to merge 2 commits intolaravel:13.xfrom
sumaiazaman:feat/failover-store-flush-locks

Conversation

@sumaiazaman
Copy link
Copy Markdown
Contributor

Summary

  • FailoverStore now implements CanFlushLocks and the flushLocks() / hasSeparateLockStore() methods
  • Cache::flushLocks() now works when the failover cache driver is in use

Context

Every cache store that ships with Laravel implements CanFlushLocks:

Store CanFlushLocks before CanFlushLocks after
ArrayStore
DatabaseStore
FileStore
RedisStore
FailoverStore

FailoverStore already implements LockProvider (for acquiring locks), but calling Cache::flushLocks() with the failover driver threw "This cache store does not support flushing locks." because the store didn't implement CanFlushLocks.

Solution

Added CanFlushLocks to the class declaration and implemented two methods:

flushLocks(): bool — iterates through every backing store and calls flushLocks() on those that implement CanFlushLocks. Unlike attemptOnAllStores() (which returns on the first success), this flushes all stores, because locks may have been acquired on any of them during failover.

hasSeparateLockStore(): bool — returns true. The failover store delegates entirely to its backing stores, each of which manages lock storage independently.

Example

Before:

// config/cache.php: 'default' => 'failover'
Cache::flushLocks(); // throws BadMethodCallException: "This cache store does not support flushing locks."

After:

Cache::flushLocks(); // true — flushes locks on all backing stores

Why no breaking changes

This is a purely additive change. No existing method signatures are modified, and no existing callers are affected.

Changes

  • src/Illuminate/Cache/FailoverStore.php — added CanFlushLocks import, added to class declaration, implemented flushLocks() and hasSeparateLockStore()
  • tests/Cache/CacheFailoverStoreTest.php — new unit test file

Test Plan

  • php83 vendor/bin/phpunit tests/Cache/CacheFailoverStoreTest.php — all 3 tests pass

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