The `ttl-set` package provides a JavaScript `Set`-like data structure where each entry automatically expires after a specified time-to-live (TTL). It is currently at version 1.0.0, indicating a stable API with a well-defined feature set. The library's release cadence is likely infrequent due to its focused and stable utility functionality, serving as a robust solution for simple, time-bound caching needs. Its primary differentiator is the direct integration of TTL expiration into the `Set` interface, distinguishing it from general-purpose `Set` objects or more complex caching libraries that might offer LRU/LFU policies. This makes it ideal for scenarios requiring a basic, memory-efficient, and self-cleaning collection of unique values, such as tracking active sessions, recently seen items, or implementing basic rate-limiting without external dependencies or elaborate configuration. The core API mirrors `Set.prototype`, offering `add`, `has`, `clear`, and `size`.
npm install ttl-setVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `TTLSet`, add elements, and observe their automatic expiration over time based on the defined TTL.
If refresh-on-access or refresh-on-update behavior is desired, you must manually `delete` and then `add` the value again, or consider a different caching library.
For extremely high-volume, long-lived caches, evaluate if `ttl-set`'s individual timer approach is suitable or if a more advanced caching strategy (e.g., using a single timer to scan for expirations or an external cache service) is required.
Always instantiate `TTLSet` using `new TTLSet(ttl)`. For ESM, ensure `import TTLSet from 'ttl-set';` is used. For CommonJS, `const TTLSet = require('ttl-set');`.Use `cache.has(value)` to check for existence and `cache.add(value)` to add elements. If you need key-value pairs with TTL, consider a `TTLMap` implementation or build one using `ttl-set` for keys and a regular `Map` for values.
No dependency data recorded yet.