Idempotency¶
rn_forge.django.drf.idempotency
¶
Django-cache idempotency storage and DRF integration.
CacheIdempotencyStore(*, timeout=86400, cache_alias='default')
¶
Implement rn_forge.web.IdempotencyStore over a shared Django cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
Seconds a claim and its stored response live. Defaults to 24h. |
86400
|
cache_alias
|
str
|
The |
'default'
|
cache_key(scope, key)
staticmethod
¶
Return the cache key for key within scope.
The length-prefixed scope prevents collisions between endpoint or tenant namespaces.
complete(*, scope, key, status, response_body)
¶
See :meth:rn_forge.web.IdempotencyStore.complete.
record_or_replay(*, scope, key, request_body)
¶
See :meth:rn_forge.web.IdempotencyStore.record_or_replay.
idempotent(store, *, scope, header=IDEMPOTENCY_KEY_HEADER)
¶
Decorate a DRF handler method so an unsafe request executes once per key.
Safe methods bypass the store. A missing key on an unsafe method raises
:class:rn_forge.web.IdempotencyKeyRequired (400); a replay returns the
stored status and body verbatim; the same key with a different body raises
:class:rn_forge.web.IdempotencyKeyReuse (422); a duplicate while the
original is still in flight raises
:class:rn_forge.web.IdempotencyKeyInFlight (409).
Example::
class ChargeView(APIView):
@idempotent(CacheIdempotencyStore(), scope="charges")
def post(self, request): ...
Raises:
| Type | Description |
|---|---|
AppException
|
The handler returned a streaming response, which has no body to store. |