{"record":{"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":"warning","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/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Cache/MemoizedStore.php#L158-L194","documentation":"MemoizedStore wraps an underlying Repository and delegates lock() to it. If the wrapped store does not implement Illuminate\\Contracts\\Cache\\LockProvider, no locks are available and the call is refused with BadMethodCallException. The memoized layer itself has no lock semantics; it depends entirely on the underlying store.","triggerScenarios":"Calling Cache::memo()->lock('key') or any code path that obtains the memoized repository and calls ->lock() when the underlying driver (e.g., array, dynamodb without lock support, null driver) does not implement LockProvider.","commonSituations":"Test code using Cache::memo() with CACHE_DRIVER=array and attempting to acquire a lock. Production code that calls Cache::memo()->lock() on a driver like 'file' or 'dynamodb' that does provide locks via a different interface but the memo wrapper check is strict on LockProvider.","solutions":["Call lock() on the underlying non-memoized store: Cache::store('redis')->lock('key') instead of Cache::memo()->lock('key').","Switch the memoized driver's underlying store to one implementing LockProvider (redis, database, memcached, file).","Guard calls with Cache::memo()->getStore() instanceof LockProvider before invoking lock()."],"exampleFix":"// before\nCache::memo()->lock('export-' . $user->id, 60);\n// underlying store is 'array' -> BadMethodCallException\n\n// after\nif (Cache::store(config('cache.memo'))->getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider) {\n    Cache::store(config('cache.memo'))->lock('export-' . $user->id, 60)->block(5);\n} else {\n    Cache::store('redis')->lock('export-' . $user->id, 60)->block(5);\n}","handlingStrategy":"type-guard","validationCode":"// Validate the memoized store's underlying store supports locks before calling lock()\n$store = Cache::memo()->getStore();\nif (! $store->getRepository()->getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider) {\n    throw new \\RuntimeException('Underlying memo store does not support locks.');\n}\n$store->lock('key', 60);","typeGuard":"function memoStoreSupportsLocks(\\Illuminate\\Cache\\Repository $repo): bool\n{\n    return $repo->getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider;\n}","tryCatchPattern":"try {\n    Cache::memo()->lock('key', 60);\n} catch (\\BadMethodCallException $e) {\n    if (str_contains($e->getMessage(), 'does not support locks')) {\n        // fall back to a lock-supporting store\n        return Cache::store('redis')->lock('key', 60);\n    }\n    throw $e;\n}","preventionTips":["Acquire locks on a dedicated lock-supporting store, not on Cache::memo().","Add an arch test that lock() calls go through Cache::store('redis'|'database').","Document which stores implement LockProvider in the project cache guide."],"tags":["cache","memoized","locks","bad-method-call"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}