Feature request: add local cache to Idempotency persistence layer #1299
Labels
completed
This item is complete and has been merged/shipped
feature-request
This item refers to a feature request for an existing or new utility
idempotency
This item relates to the Idempotency Utility
Milestone
Use case
To improve performance, the Idempotency utility can be configured to use a local cache to store idempotency records.
Solution/User Experience
Optionally, the user can also set a max number of items to store in the cache before older ones start get evicted:
Use the Python implementation as reference and extend the
BasePersistenceLayer
.The
IdempotencyConfig
class already supports theuseLocalCache
field. ThelocalCacheMaxItems
one is not yet implemented and should default to256
.Below comments from @dreamorosi:
Contrary to Python, Node.js doesn't have a LRU Cache in its standard library. Looking at popular libraries there seem to be two options:
lru_map
3.7M weekly downloads - last published 3 yrs ago - 27.9 kB unpacked sizelru-cache
123M weekly downloads - last published 2 days ago - 638 kBBoth libraries appear to be extremely popular. The former,
lru_map
is a lot less popular than the other and hasn't been updated in a long time, however it has a small footprint when compared to the other alternative.In terms of features, the
lru-cache
module has a wide range of features like TTL, retrieval functions from remote, etc. - all these features contribute to the significant size. On the other hand,lru_map
only supports one config/feature: the ability to set a maximum of items to keep in the cache.Our currently published Powertools utilities range between 70 and 110 kB. Given that
lru_map
supports exactly the features that we need, has zero dependencies, and a relatively stable implementation, I'm inclined to recommend this module over the other larger and more feature complete one.Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: