Package com.tnsai.idempotency
Class InMemoryIdempotencyStore
java.lang.Object
com.tnsai.idempotency.InMemoryIdempotencyStore
- All Implemented Interfaces:
IdempotencyStore
Default
IdempotencyStore — process-local, ephemeral, no
external dependencies (issue #91). Suitable for single-process
deployments and tests; production multi-process deployments should
pick a Redis or Postgres adapter (separate follow-up PRs) so dedup
survives process restarts and works across instances.
Eviction is lazy: an expired entry stays in the map until the next
get(String) for that key, at which point it is removed and
the lookup returns empty. This keeps the put/get path lock-free at
the cost of one map slot per expired-but-not-yet-touched key. For
deployments that hold a steady set of keys, that's free; for
deployments where the key space grows unboundedly, prefer the
external-store adapters which can scan + evict in the background.
- Since:
- 0.5.0 (issue #91)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLook up a cached entry.voidinvalidate(String key) Remove the entry forkeyif any.voidput(String key, IdempotencyEntry entry, Duration ttl) Store an entry underkeywith the given TTL.intsize()Approximate entry count.
-
Constructor Details
-
InMemoryIdempotencyStore
public InMemoryIdempotencyStore()
-
-
Method Details
-
get
Description copied from interface:IdempotencyStoreLook up a cached entry. Returns empty when no entry exists OR when the entry's TTL has elapsed.- Specified by:
getin interfaceIdempotencyStore
-
put
Description copied from interface:IdempotencyStoreStore an entry underkeywith the given TTL. SubsequentIdempotencyStore.get(java.lang.String)calls within the TTL window return this entry. Overwrites any prior entry for the same key.- Specified by:
putin interfaceIdempotencyStore
-
invalidate
Description copied from interface:IdempotencyStoreRemove the entry forkeyif any. No-op if the key is not present.- Specified by:
invalidatein interfaceIdempotencyStore
-
size
public int size()Description copied from interface:IdempotencyStoreApproximate entry count. Intended for monitoring / smoke-testing ("cache has grown to 10M entries, check your TTL"). Implementations may return an eventually-consistent snapshot.- Specified by:
sizein interfaceIdempotencyStore
-