{"id":"691fe2d0a423641e","repo":"laravel/framework","slug":"this-lock-driver-does-not-support-refreshing-locks","errorCode":null,"errorMessage":"This lock driver does not support refreshing locks.","messagePattern":"This lock driver does not support refreshing locks\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Illuminate/Cache/Lock.php","lineNumber":149,"sourceCode":"            try {\n                return $callback();\n            } finally {\n                $this->release();\n            }\n        }\n\n        return true;\n    }\n\n    /**\n     * Attempt to refresh the lock for the given number of seconds.\n     *\n     * @param  int|null  $seconds\n     * @return bool\n     */\n    public function refresh($seconds = null)\n    {\n        throw new RuntimeException('This lock driver does not support refreshing locks.');\n    }\n\n    /**\n     * Returns the current owner of the lock.\n     *\n     * @return string\n     */\n    public function owner()\n    {\n        return $this->owner;\n    }\n\n    /**\n     * Determine if the lock is currently held by any process.\n     *\n     * @return bool\n     */\n    public function isLocked(): bool","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/Lock.php#L131-L167","documentation":"The abstract base Lock::refresh() throws RuntimeException because not all lock backends support extending a held lock's TTL. Drivers that support it (e.g. RedisLock, PhpRedisLock) override refresh(); drivers that don't (e.g. ArrayLock, DynamoDbLock) inherit the throwing implementation.","triggerScenarios":"Acquiring a lock via Cache::lock('x') then calling $lock->refresh(30) when the underlying store is array, file, or another driver whose Lock subclass does not override refresh().","commonSituations":"Using the array driver in tests and exercising long-running lock code that calls refresh(). Switching a cache driver from redis to array/file and forgetting that refresh() is unsupported. Writing library code that assumes all locks are refreshable.","solutions":["Use a refresh-capable driver (redis, database) if your workload relies on extending locks.","Guard the call: check the concrete class before calling refresh().","Instead of refresh(), release and re-acquire the lock to extend ownership on drivers without native refresh.","In tests, mock the lock or use a redis-compatible fake if refresh() must succeed."],"exampleFix":"// before\n$lock = Cache::store('array')->lock('orders', 60);\n$lock->block(5);\n$lock->refresh(60); // throws on array driver\n\n// after (release + re-acquire)\n$lock->release();\n$lock = Cache::store('array')->lock('orders', 60);\n$lock->block(5);\n// or switch store to redis/database for refresh support","handlingStrategy":"type-guard","validationCode":"$lock = Cache::lock('orders', 60);\n$reflectable = new \\ReflectionMethod($lock, 'refresh');\nif ($reflectable->getDeclaringClass()->getName() === \\Illuminate\\Cache\\Lock::class) {\n    throw new \\RuntimeException('This lock driver does not support refresh(); use redis/database.');\n}\n$lock->refresh(60);","typeGuard":"function lockSupportsRefresh(\\Illuminate\\Contracts\\Cache\\Lock $lock): bool\n{\n    return (new \\ReflectionMethod($lock, 'refresh'))\n        ->getDeclaringClass()->getName() !== \\Illuminate\\Cache\\Lock::class;\n}","tryCatchPattern":"try {\n    $lock->refresh(60);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'does not support refreshing')) {\n        $lock->release();\n        $lock = Cache::lock('orders', 60);\n        $lock->block(5);\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Use redis or database drivers when locks need extending.","Check the concrete lock class before refresh().","Prefer release()+re-acquire() over refresh() in driver-agnostic code.","Document which drivers support refresh() in project notes."],"tags":["cache","locks","unsupported-operation","drivers"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}