2021-07-10 node/Lambda in memory cache module
Ideas
Looking at implementing a simple standardized in memory cache, in Lambda this will mean per container, re-used within the single invocation or across multiple invocations with the same container (understand containers normally shut down within about 2 hours, so that would be the max duration of the cache).
This is not a strong nor persistent cache, and is not shared across multiple Lambda containers or Lambda functions, for strong persistence DynamoDB could be used, for cache shared across all containers ElastiCache etc could be used.
In memory cache should only be used for simple storage of eg single lookups to Dynamo, which are already cheap and fast, but will be a little cheaper and faster if we use up available ram caching the results within the Lambda function.
Options
https://github.com/medikoo/memoizee#readme Chose this module.
https://github.com/node-cache/node-cache Is one of the most popular, did not choose because did not seem to have a limited that automatically deletes the oldest/least frequently used cache entry. Want this because Lambda functions will have an easily reached ram limit, but we still want to save new cache entries. node-cache has a maxKeys setting, but simply throws an error if the limit is reached.
https://github.com/BryanDonovan/node-cache-manager#readme Is nice that it allows multiple store engines, but more complex, code seems older, less used, and does not have method to automatically delete the oldest/least frequently used cache entries.