{"id":"75c936a1a7cba417","repo":"laravel/framework","slug":"this-cache-store-does-not-support-locks","errorCode":null,"errorMessage":"This cache store does not support locks.","messagePattern":"This cache store does not support locks\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Cache/MemoizedStore.php","lineNumber":176,"sourceCode":"        unset($this->cache[$this->prefix($key)]);\n\n        return $this->repository->forever($key, $value);\n    }\n\n    /**\n     * Get a lock instance.\n     *\n     * @param  string  $name\n     * @param  int  $seconds\n     * @param  string|null  $owner\n     * @return \\Illuminate\\Contracts\\Cache\\Lock\n     *\n     * @throws \\BadMethodCallException\n     */\n    public function lock($name, $seconds = 0, $owner = null)\n    {\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()->lock(...func_get_args());\n    }\n\n    /**\n     * Restore a lock instance using the owner identifier.\n     *\n     * @param  string  $name\n     * @param  string  $owner\n     * @return \\Illuminate\\Contracts\\Cache\\Lock\n     *\n     * @throws \\BadMethodCallException\n     */\n    public function restoreLock($name, $owner)\n    {\n        if (! $this->repository->getStore() instanceof LockProvider) {\n            throw new BadMethodCallException('This cache store does not support locks.');","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/MemoizedStore.php#L158-L194","documentation":"MemoizedStore::lock() throws BadMethodCallException when the wrapped repository's underlying store is not an instance of LockProvider. The memoized store delegates lock acquisition but cannot fabricate locking on a store (e.g. NullStore, file without locks) that has no lock provider.","triggerScenarios":"Calling Cache::memo()->lock('x') (or resolving a memoized store) when the backing store's driver is null/file/dynamodb configured in a way that the store object is not a LockProvider. Also reached when the default cache driver is such a store.","commonSituations":"Setting CACHE_STORE=null or CACHE_STORE=file in tests and then exercising code that requests locks via the memoized cache. Wrapping a custom store that omits the LockProvider interface.","solutions":["Switch the cache driver to one that implements LockProvider (redis, database, array, memcached, dynamodb).","If you need locks, do not back the memoized store with NullStore or a non-LockProvider custom store.","Implement LockProvider on your custom store class so lock()/restoreLock() are available."],"exampleFix":"// before\n// CACHE_STORE=null\nCache::memo()->lock('orders')->block(5); // throws\n\n// after\n// CACHE_STORE=redis\nCache::memo()->lock('orders')->block(5);\n// or implement LockProvider on your custom store","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\\LockProvider) {\n    throw new \\RuntimeException('Backing cache store does not support locks; switch driver.');\n}\n$store->lock('x');","typeGuard":"function memoStoreSupportsLocks(\\Illuminate\\Cache\\MemoizedStore $store): bool\n{\n    return $store->getRepository()->getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider;\n}","tryCatchPattern":"try {\n    Cache::memo()->lock('x')->block(5);\n} catch (\\BadMethodCallException $e) {\n    if (str_contains($e->getMessage(), 'does not support locks')) {\n        Cache::store('redis')->lock('x')->block(5);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Choose a LockProvider-backed driver for the default cache.","Implement LockProvider on custom stores.","Guard instanceof LockProvider before calling lock().","Document driver lock capabilities."],"tags":["cache","memoized-store","locks","drivers"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}