{"id":"04e9c28e7147d10f","repo":"laravel/framework","slug":"this-cache-store-does-not-support-locks-04e9c2","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/Repository.php","lineNumber":742,"sourceCode":"     * @return TReturn\n     *\n     * @throws \\Illuminate\\Contracts\\Cache\\LockTimeoutException\n     */\n    public function withoutOverlapping($key, callable $callback, $lockFor = 0, $waitFor = 10, $owner = null)\n    {\n        return $this->store->lock(enum_value($key), $lockFor, $owner)->block($waitFor, $callback);\n    }\n\n    /**\n     * Funnel a callback for a maximum number of simultaneous executions.\n     *\n     * @param  \\UnitEnum|string  $name\n     * @return \\Illuminate\\Cache\\Limiters\\ConcurrencyLimiterBuilder\n     */\n    public function funnel($name)\n    {\n        if (! $this->store instanceof LockProvider) {\n            throw new BadMethodCallException('This cache store does not support locks.');\n        }\n\n        return new ConcurrencyLimiterBuilder($this, enum_value($name));\n    }\n\n    /**\n     * Remove an item from the cache.\n     *\n     * @param  \\UnitEnum|array|string  $key\n     * @return bool\n     */\n    public function forget($key)\n    {\n        $key = enum_value($key);\n\n        $this->event(new ForgettingKey($this->getName(), $key));\n\n        return tap($this->store->forget($this->itemKey($key)), function ($result) use ($key) {","sourceCodeStart":724,"sourceCodeEnd":760,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/Repository.php#L724-L760","documentation":"Thrown by Cache\\Repository::funnel() when the configured cache store does not implement Illuminate\\Contracts\\Cache\\LockProvider. Atomic locks (Cache::lock, block, funnel, throttle) require lock support that file/array/DynamoDB stores do not provide.","triggerScenarios":"Calling Cache::funnel('name'), Cache::lock('key'), or Cache::block('key', $cb) while CACHE_DRIVER/STORE is file, array, or another non-LockProvider store.","commonSituations":"Local dev with CACHE_STORE=file (or array in tests) hitting a Cache::lock()/->block() call that works in prod with redis/database; running queue/job code that uses Cache::lock in the testing environment.","solutions":["Switch CACHE_STORE to redis, database, memcached, or dynamodb (all implement LockProvider).","Guard the call: if (Cache::getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider) { ... }.","In phpunit set CACHE_STORE=array only for tests that don't exercise locks, and use a dedicated redis connection for lock tests.","Refactor away from locks (e.g., use a DB unique constraint or a job middleware) if no lock-capable store is available."],"exampleFix":"// before\nCache::lock('process:'.$id, 60)->block(5, fn () => doWork());\n\n// after  (env)\n// .env: CACHE_STORE=redis\n// or guard at runtime\nif (Cache::getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider) {\n    Cache::lock('process:'.$id, 60)->block(5, fn () => doWork());\n} else {\n    doWork();\n}","handlingStrategy":"validation","validationCode":"if (! (Cache::getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider)) {\n    // locks unavailable; choose a fallback path\n}","typeGuard":"function cacheSupportsLocks(): bool {\n    return Cache::getStore() instanceof \\Illuminate\\Contracts\\Cache\\LockProvider;\n}","tryCatchPattern":"try {\n    Cache::lock('job:'.$id, 60)->block(5, fn () => doWork());\n} catch (\\BadMethodCallException $e) {\n    // store lacks lock support; run without a lock or fail loudly\n    doWork();\n}","preventionTips":["Keep CACHE_STORE consistent between environments that exercise locks (redis/database).","Guard lock usage with an instanceof LockProvider check.","In tests, only assert lock behavior when the backing store supports it."],"tags":["cache","locks","config","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}