Configuration
After publishing the config file, all options are available in config/idempotency.php. If you haven't published it yet, see Installation.
Full Configuration File
<?php
return [
'default' => 'cache',
'lock_wait' => [
'timeout' => 10,
'strategy' => 'wait',
],
'request' => [
'idempotent_methods' => ['POST', 'PATCH'],
'middleware_alias' => 'idempotent',
'store' => 'cache',
'header' => [
'idempotency_key' => 'Idempotency-Key',
'idempotency_relay' => 'Idempotency-Relay',
]
],
'stores' => [
'cache' => [
'driver' => 'default',
'ttl' => 86400,
],
'database' => [
'driver' => 'default',
'ttl' => 86400,
'table_name' => 'idempotency',
]
]
];
Default Store
'default' => 'cache',
The default store used across the package. Accepts cache or database. See Stores for details on choosing between them.
Lock Wait
Controls behavior when two concurrent requests arrive with the same idempotency key.
'lock_wait' => [
'strategy' => 'wait', // wait|exception
'timeout' => 10,
],
| Option | Values | Description |
|---|---|---|
strategy | wait / exception | wait holds the second request until the first completes. exception throws ConcurrentInvocationException immediately |
timeout | integer (seconds) | How long to wait before throwing LockWaitExceededException. Only applies when strategy is wait |
Request
Options specific to HTTP middleware behavior.
'request' => [
'idempotent_methods' => ['POST', 'PATCH'],
'middleware_alias' => 'idempotent',
'store' => 'cache',
'header' => [
'idempotency_key' => 'Idempotency-Key',
'idempotency_relay' => 'Idempotency-Relay',
]
],
| Option | Default | Description |
|---|---|---|
idempotent_methods | ['POST', 'PATCH'] | HTTP methods that idempotency is applied to |
middleware_alias | idempotent | Alias used to register the middleware on routes |
store | cache | Store used specifically for HTTP requests. Overrides default |
header.idempotency_key | Idempotency-Key | Header name the client sends with the request |
header.idempotency_relay | Idempotency-Relay | Header name added to replayed responses |
Stores
Cache
'cache' => [
'driver' => 'default',
'ttl' => 86400,
],
| Option | Default | Description |
|---|---|---|
driver | default | Cache driver to use. default uses the Laravel default cache driver |
ttl | 86400 | Seconds to keep the idempotency record. Default is 24 hours |
tip
Redis is recommended for the Cache store — it supports atomic locks required for concurrent request handling.
Database
'database' => [
'driver' => 'default',
'ttl' => 86400,
'table_name' => 'idempotency',
],
| Option | Default | Description |
|---|---|---|
driver | default | Database driver to use |
ttl | 86400 | Seconds to keep the idempotency record. Default is 24 hours |
table_name | idempotency | Table name created by the migration |