laravel/framework · error · BadMethodCallException

This cache store does not support flushing locks.

Error message

This cache store does not support flushing locks.

What it means

MemoizedStore::flushLocks() throws BadMethodCallException when the underlying store does not implement CanFlushLocks. The memoized wrapper can only delegate lock flushing to a store that opts in via the CanFlushLocks contract; stores that don't (e.g. NullStore, some custom stores) cannot flush locks.

Source

Thrown at src/Illuminate/Cache/MemoizedStore.php:210

    {
        if (! $this->repository->getStore() instanceof LockProvider) {
            throw new BadMethodCallException('This cache store does not support locks.');
        }

        return $this->repository->getStore()->restoreLock(...func_get_args());
    }

    /**
     * Flush all locks managed by the store.
     *
     * @throws \BadMethodCallException
     */
    public function flushLocks(): bool
    {
        $store = $this->repository->getStore();

        if (! $store instanceof CanFlushLocks) {
            throw new BadMethodCallException('This cache store does not support flushing locks.');
        }

        return $store->flushLocks();
    }

    /**
     * Determine if the lock store is separate from the cache store.
     */
    public function hasSeparateLockStore(): bool
    {
        $store = $this->repository->getStore();

        return $store instanceof CanFlushLocks && $store->hasSeparateLockStore();
    }

    /**
     * Adjust the expiration time of a cached item.
     *

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Implement Illuminate\Contracts\Cache\CanFlushLocks (flushLocks() and hasSeparateLockStore()) on your custom store.
  2. Switch to a built-in store that already implements CanFlushLocks (array, database, file, redis) when flushLocks() is needed.
  3. Guard the call: check instanceof CanFlushLocks before invoking flushLocks().

Example fix

// before
// backing store = NullStore (not CanFlushLocks)
Cache::memo()->getStore()->flushLocks(); // throws

// after
use Illuminate\Contracts\Cache\CanFlushLocks;

if (Cache::memo()->getStore() instanceof CanFlushLocks) {
    Cache::memo()->getStore()->flushLocks();
}
// or switch CACHE_STORE to a CanFlushLocks driver
Defensive patterns

Strategy: type-guard

Validate before calling

$store = Cache::memo()->getStore();
$backing = $store instanceof \Illuminate\Cache\MemoizedStore ? $store->getRepository()->getStore() : $store;
if (! $backing instanceof \Illuminate\Contracts\Cache\CanFlushLocks) {
    throw new \RuntimeException('Backing store cannot flushLocks(); switch driver.');
}
$store->flushLocks();

Type guard

function memoStoreCanFlushLocks(\Illuminate\Cache\MemoizedStore $store): bool
{
    return $store->getRepository()->getStore() instanceof \Illuminate\Contracts\Cache\CanFlushLocks;
}

Try / catch

try {
    Cache::memo()->getStore()->flushLocks();
} catch (\BadMethodCallException $e) {
    if (str_contains($e->getMessage(), 'does not support flushing locks')) {
        Cache::memo()->flush();
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: Calling Cache::memo()->getStore()->flushLocks() when the backing store is NullStore or a custom store that implements Store but not CanFlushLocks. Reached by teardown/cleanup code that clears locks between operations.

Common situations: Tests with CACHE_STORE=null and a memoized cache, exercising a flushLocks() code path. Custom cache stores that predate the CanFlushLocks contract. Refactoring from a lock-capable driver to null during a maintenance window.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/ad60aa80f2cc9530.json. Report an issue: GitHub.