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

Thrown by Cache\Repository::flushLocks() when the store does not implement Illuminate\Cache\CanFlushLocks. Even lock-capable stores (redis/database/memcached) only flush locks if they specifically opt in via that interface.

Source

Thrown at src/Illuminate/Cache/Repository.php:823

            $this->event(new CacheFlushed($this->getName()));
        } else {
            $this->event(new CacheFlushFailed($this->getName()));
        }

        return $result;
    }

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

        if (! $this->supportsFlushingLocks()) {
            throw new BadMethodCallException('This cache store does not support flushing locks.');
        }

        $this->event(new CacheLocksFlushing($this->getName()));

        $result = $store->flushLocks();

        if ($result) {
            $this->event(new CacheLocksFlushed($this->getName()));
        } else {
            $this->event(new CacheLocksFlushFailed($this->getName()));
        }

        return $result;
    }

    /**
     * Begin executing a new tags operation if the store supports it.
     *

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Guard with the provided capability check: if (Cache::supportsFlushingLocks()) { Cache::flushLocks(); }.
  2. Switch to a store that implements CanFlushLocks (redis/database) for the environment that needs it.
  3. If you wrote a custom Store, implement CanFlushLocks::flushLocks() and clear the lock namespace.
  4. In tests, reset by calling Cache::flush() or by using a fresh array store per test instead of flushLocks().

Example fix

// before
Cache::flushLocks();

// after
if (Cache::supportsFlushingLocks()) {
    Cache::flushLocks();
}
Defensive patterns

Strategy: validation

Validate before calling

if (! Cache::supportsFlushingLocks()) {
    // skip flushLocks() or use Cache::flush()
}

Type guard

function canFlushLocks(): bool {
    return Cache::supportsFlushingLocks();
}

Try / catch

try {
    Cache::flushLocks();
} catch (\BadMethodCallException $e) {
    // store can't flush locks; fall back to flush() or no-op
}

Prevention

When it happens

Trigger: Calling Cache::flushLocks() (e.g., in a test teardown or maintenance command) on a store that lacks CanFlushLocks, including array/file stores and some custom adapters.

Common situations: Test cleanup that calls Cache::flushLocks() while CACHE_STORE=array; a custom Store subclass that implements LockProvider but forgot flushLocks(); a maintenance command run in an env whose driver does not support lock flushing.

Related errors


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