{"id":"ad60aa80f2cc9530","repo":"laravel/framework","slug":"this-cache-store-does-not-support-flushing-locks","errorCode":null,"errorMessage":"This cache store does not support flushing locks.","messagePattern":"This cache store does not support flushing locks\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/MemoizedStore.php","lineNumber":210,"sourceCode":"    {\n        if (! $this->repository->getStore() instanceof LockProvider) {\n            throw new BadMethodCallException('This cache store does not support locks.');\n        }\n\n        return $this->repository->getStore()->restoreLock(...func_get_args());\n    }\n\n    /**\n     * Flush all locks managed by the store.\n     *\n     * @throws \\BadMethodCallException\n     */\n    public function flushLocks(): bool\n    {\n        $store = $this->repository->getStore();\n\n        if (! $store instanceof CanFlushLocks) {\n            throw new BadMethodCallException('This cache store does not support flushing locks.');\n        }\n\n        return $store->flushLocks();\n    }\n\n    /**\n     * Determine if the lock store is separate from the cache store.\n     */\n    public function hasSeparateLockStore(): bool\n    {\n        $store = $this->repository->getStore();\n\n        return $store instanceof CanFlushLocks && $store->hasSeparateLockStore();\n    }\n\n    /**\n     * Adjust the expiration time of a cached item.\n     *","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/MemoizedStore.php#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Implement Illuminate\\Contracts\\Cache\\CanFlushLocks (flushLocks() and hasSeparateLockStore()) on your custom store.","Switch to a built-in store that already implements CanFlushLocks (array, database, file, redis) when flushLocks() is needed.","Guard the call: check instanceof CanFlushLocks before invoking flushLocks()."],"exampleFix":"// before\n// backing store = NullStore (not CanFlushLocks)\nCache::memo()->getStore()->flushLocks(); // throws\n\n// after\nuse Illuminate\\Contracts\\Cache\\CanFlushLocks;\n\nif (Cache::memo()->getStore() instanceof CanFlushLocks) {\n    Cache::memo()->getStore()->flushLocks();\n}\n// or switch CACHE_STORE to a CanFlushLocks driver","handlingStrategy":"type-guard","validationCode":"$store = Cache::memo()->getStore();\n$backing = $store instanceof \\Illuminate\\Cache\\MemoizedStore ? $store->getRepository()->getStore() : $store;\nif (! $backing instanceof \\Illuminate\\Contracts\\Cache\\CanFlushLocks) {\n    throw new \\RuntimeException('Backing store cannot flushLocks(); switch driver.');\n}\n$store->flushLocks();","typeGuard":"function memoStoreCanFlushLocks(\\Illuminate\\Cache\\MemoizedStore $store): bool\n{\n    return $store->getRepository()->getStore() instanceof \\Illuminate\\Contracts\\Cache\\CanFlushLocks;\n}","tryCatchPattern":"try {\n    Cache::memo()->getStore()->flushLocks();\n} catch (\\BadMethodCallException $e) {\n    if (str_contains($e->getMessage(), 'does not support flushing locks')) {\n        Cache::memo()->flush();\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Implement CanFlushLocks on custom stores.","Guard instanceof CanFlushLocks before flushLocks().","Use a built-in store that supports lock flushing for teardown code."],"tags":["cache","memoized-store","locks","drivers"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}