Skip to content

Commit f386dcf

Browse files
committed
document cache failover
1 parent f927502 commit f386dcf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cache.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Atomic Locks](#atomic-locks)
1515
- [Managing Locks](#managing-locks)
1616
- [Managing Locks Across Processes](#managing-locks-across-processes)
17+
- [Cache Failover](#cache-failover)
1718
- [Adding Custom Cache Drivers](#adding-custom-cache-drivers)
1819
- [Writing the Driver](#writing-the-driver)
1920
- [Registering the Driver](#registering-the-driver)
@@ -529,6 +530,31 @@ If you would like to release a lock without respecting its current owner, you ma
529530
Cache::lock('processing')->forceRelease();
530531
```
531532

533+
<a name="cache-failover"></a>
534+
## Cache Failover
535+
536+
The `failover` cache driver provides automatic failover functionality when interacting with the cache. If the primary cache store fails for any reason, Laravel will automatically attempt to use the next configured store in the list. This is particularly useful for ensuring high availability in production environments where cache reliability is critical.
537+
538+
To configure a failover cache store, specify the `failover` driver and provide an array of store names to attempt in order. By default, Laravel includes an example failover configuration in your application's `config/cache.php` configuration file:
539+
540+
```php
541+
'failover' => [
542+
'driver' => 'failover',
543+
'stores' => [
544+
'database',
545+
'array',
546+
],
547+
],
548+
```
549+
550+
Once you have configured a store that uses the `failover` driver, you will probably want to set the failover store as your default cache store in your application's `.env` file:
551+
552+
```ini
553+
CACHE_STORE=failover
554+
```
555+
556+
When a cache store operation fails and failover is activated, Laravel will dispatch the `Illuminate\Cache\Events\CacheFailedOver` event, allowing you to report or log that a cache store has failed.
557+
532558
<a name="adding-custom-cache-drivers"></a>
533559
## Adding Custom Cache Drivers
534560

0 commit comments

Comments
 (0)