{"id":"263a8b06702e388e","repo":"laravel/framework","slug":"flushing-locks-is-only-supported-when-the-lock-sto-263a8b","errorCode":null,"errorMessage":"Flushing locks is only supported when the lock store is separate from the cache store.","messagePattern":"Flushing locks is only supported when the lock store is separate from the cache store\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"src/Illuminate/Cache/DatabaseStore.php","lineNumber":465,"sourceCode":"     */\n    public function flush()\n    {\n        $this->table()->delete();\n\n        return true;\n    }\n\n    /**\n     * Remove all locks from the store.\n     *\n     * @return bool\n     *\n     * @throws \\RuntimeException\n     */\n    public function flushLocks(): bool\n    {\n        if (! $this->hasSeparateLockStore()) {\n            throw new RuntimeException('Flushing locks is only supported when the lock store is separate from the cache store.');\n        }\n\n        $this->lockTable()->delete();\n\n        return true;\n    }\n\n    /**\n     * Get a query builder for the cache table.\n     *\n     * @return \\Illuminate\\Database\\Query\\Builder\n     */\n    protected function table()\n    {\n        return $this->connection->table($this->table);\n    }\n\n    /**","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Cache/DatabaseStore.php#L447-L483","documentation":"DatabaseStore::flushLocks() throws if hasSeparateLockStore() is false, which occurs when the lock table name equals the cache table name ($this->lockTable === $this->table). Flushing only locks is destructive when cache rows and lock rows share one table; the guard prevents wiping cache data.","triggerScenarios":"Configuring a database cache store with 'lock_table' set to the same value as 'table' (e.g. both 'cache'), then calling Cache::store('db')->getStore()->flushLocks() or any code path that invokes it (e.g. the Artisan cache:clear-locks command).","commonSituations":"Setting lock_table => 'cache' to reuse the migrations' cache table for locks. Omitting lock_table and having previously renamed the cache table to 'cache_locks'. Migrating an older app where locks were stored alongside cache entries.","solutions":["Set a distinct 'lock_table' (default 'cache_locks') in config/cache.php so hasSeparateLockStore() returns true.","Optionally set a separate 'lock_connection' to put locks on a different DB connection entirely.","Run the migration php artisan cache:table / php artisan cache:locks-table to create the dedicated locks table.","If you intentionally share one table, call flush() to clear everything rather than flushLocks()."],"exampleFix":"// before\n'stores' => [\n    'db' => [\n        'driver' => 'database',\n        'table' => 'cache',\n        'lock_table' => 'cache', // same table -> throws\n    ],\n],\n\n// after\n'stores' => [\n    'db' => [\n        'driver' => 'database',\n        'table' => 'cache',\n        'lock_table' => 'cache_locks',\n        'lock_connection' => null,\n    ],\n],","handlingStrategy":"validation","validationCode":"$store = Cache::store('db')->getStore();\nif ($store instanceof \\Illuminate\\Cache\\DatabaseStore && ! $store->hasSeparateLockStore()) {\n    throw new \\RuntimeException('Database cache lock_table must differ from cache table to flushLocks().');\n}\n$store->flushLocks();","typeGuard":"function databaseCacheHasSeparateLocks(\\Illuminate\\Contracts\\Cache\\Store $store): bool\n{\n    return $store instanceof \\Illuminate\\Cache\\DatabaseStore\n        && $store->hasSeparateLockStore();\n}","tryCatchPattern":"try {\n    Cache::store('db')->getStore()->flushLocks();\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'lock store is separate')) {\n        Cache::store('db')->flush();\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Always set a distinct lock_table in database store config.","Run cache:locks-table migration to create the dedicated table.","Guard hasSeparateLockStore() before flushLocks() in teardown code."],"tags":["cache","database-store","locks","configuration"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}