
Security News
Packagist Urges Immediate Composer Update After GitHub Actions Token Leak
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.
safe-memory-cache
Advanced tools
Secure and size-limited in-memory cache for Node.js and browsers.
Updated with defensive coding (for prototype poisoning immunity)
__proto__) or a prototype poisoning of intrinsicsdelete (and no memory leaks caused by delete), plays well with garbage collector. But also doesn't drop the whole cache when full, frees up graduallyvar {safeMemoryCache} = require('safe-memory-cache')
var cache = safeMemoryCache(options)
cache.set("key1","value1")
cache.get("key1") === "value1"
cache.clear()
cache.get("key1") === undefined
| name | type | required | description |
|---|---|---|---|
| limit | number | Y | Maximum number of items to store in cache. When cache length is close to the limit, oldest items are removed to make more room. |
| maxTTL | number | N | Time in miliseconds within which an element should no longer be in cache if it was not accessed. Actual time is approximate and will be less or equal maxTTL |
| buckets | number | N | Overrides the number of buckets used internally. Default is 2 |
| cleanupListener | function | N | Calls the function with a storage bucket that's been removed |
| retainUsed | boolean | N | Keep items longer than the maxTTL if they are used |
If you expect N keys to be used most frequently, (limit/buckets) >= N
Caching in general. When you need to cache results of some long running process or a lot of them and you don't have a strong requirement to keep every item until its exact expiry time.
Objects used for storing key/value pairs don't inherit from any of the native prototypes, nor Object
The implementation uses defensive coding to avoid relying on intrinsics that could be modified later.
delete keyword removes fields from objects, but changes the hidden class aka shape of the object which takes up some memory. As a result, adding and deleting unique fields to a plain JavaScript object may cause memory consumption to grow. Some JavaScript engines had it leak memory in various ways.
Then how do you remove old items from cache if you can't use delete?
Cache consists of a number of buckets and the oldest bucket is removed when new room is needed. Therefore the oldest (1/buckets) of entries gets removed.
There's only one interval created per cache instance.
FAQs
Secure and size-limited in-memory cache for Node.js and browsers
The npm package safe-memory-cache receives a total of 2,371 weekly downloads. As such, safe-memory-cache popularity was classified as popular.
We found that safe-memory-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.

Research
GemStuffer abuses RubyGems as an exfiltration channel, packaging scraped UK council portal data into junk gems published from new accounts.

Company News
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.