Skip to main content

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,
],
OptionValuesDescription
strategywait / exceptionwait holds the second request until the first completes. exception throws ConcurrentInvocationException immediately
timeoutinteger (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',
]
],
OptionDefaultDescription
idempotent_methods['POST', 'PATCH']HTTP methods that idempotency is applied to
middleware_aliasidempotentAlias used to register the middleware on routes
storecacheStore used specifically for HTTP requests. Overrides default
header.idempotency_keyIdempotency-KeyHeader name the client sends with the request
header.idempotency_relayIdempotency-RelayHeader name added to replayed responses

Stores​

Cache​

'cache' => [
'driver' => 'default',
'ttl' => 86400,
],
OptionDefaultDescription
driverdefaultCache driver to use. default uses the Laravel default cache driver
ttl86400Seconds 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',
],
OptionDefaultDescription
driverdefaultDatabase driver to use
ttl86400Seconds to keep the idempotency record. Default is 24 hours
table_nameidempotencyTable name created by the migration