
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@webkrafters/timed-map
Advanced tools
A timed map javascript data structure ideal for app level caching and memoization.
Name: Timed-Map
Install:
npm i -S @webkrafters/timed-map
An observable timed map javascript data structure.
Tracks and removes outdated infrequently read entries.
Ideal for in-app Application Level Memoization and Caching.
import TimedMap from '@webkrafters/timed-map';
const timedMap = new TimedMap( 1000 ); // max-age of 1-second per infrequently-used map entries
const timedMap = new TimedMap(); // defaults to 30 mins max-age
A map entry object holds the following information:
{
createdAt: int // Date in millis since epoch
key: string
value: any
ttl: int // Duration in millis
}
The TimedMap close() instance method must be called prior to deleteing or setting this map to null.
This cleans up the underlying driver along with any system resources used such as cpu timers etc.
Creates an instance of TimedMap. The optional maxEntryAgeMillis value is a class-level TTL in milliseconds applied to all entries in the map. A default of 1800000ms (i.e. 30 minutes) is assigned if omitted. Any entry which remained un-read at the end of the TTL-cycle is removed. get(key) and getEntry(key) methods constitute the only valid entry read operations. To obtain entry value without restarting the entry TTL-cycle, see the peak(key) method. Individual TTLs may be assigned to entries upon insertion. See the put(...) method. The individual TTL supersedes the class-level TTL for the individual entry.
Computed property: available entries.
Computed property: check-flag confirming a map containing no entries.
Computed property: keys to all available entries.
Property: TTL value in milliseconds applied to map entries. Setting this property triggers adjustments in the map's internal TTL cycle processes.
Computed property: number of entries in the map
Removes all entries from the map
Recommended pre-delete method: please use this method to release system resources and clean up the internal driver prior to deleteing this TimeMap instance or setting it to null.
Returns the value at key and restarts the entry's TTL cycle. This constitutes a valid read operation.
Returns the entry object residing at key. This constitutes a valid read operation.
Verifies the presence of a valid map entry at this key
Cancels event by listener function reference. Please see Events section below for more on event types and event listener.
Cancels event by event ID. Please see Events section below for more on event ID.
Subscribes to event of event type and returns unique eventId. Supply any additional info to capture as part of this event to the optional attributes object argument. Please see Events section below for more on event types, event ID and event listener.
Subscribes to one-use event of event type and returns unique eventId. Supply any additional info to capture as part of this event to the optional attributes object argument. Please see Events section below for more on event types, event ID and event listener.
Returns the value at key without restarting the entry's TTL cycle.
Creates a new map entry. If an entry existed at the key, it is overriden and returned. When the optional ttl value is supplied, it takes precedence over the class-level TTL value for calculating TTL cycles for this entry. Please see the get and getEntry methods.
If an entry existed at the key, it is removed and returned.
This map is observable and provides pathways for notifying observers of relevant changes within. For this purpose, six event types have been provided.
| Event Type | Trigger | Event Data |
|---|---|---|
| AUTO_RENEWED | After an entry read (See valid read operations above) | key: string createdAt: int previouslyCreatedAt: int |
| CLEARED | After a map clear operation | removed: MapEntry[] |
| CLOSING | The close method call prior to clean up operation. | undefined |
| PRUNED | After pruning outdated entries | removed: MapEntry[] |
| PUT | After a put method call operation | current: MapEntry previous: MapEntry |
| REMOVED | After a remove method call operation | removed: MapEntry |
Timing: Excluding the CLOSING event, all event listeners are scheduled to run at the conclusion of previously scheduled tasks. CLOSING event listeners are run immediately.
The event listener is triggered with a lone argument: the event payload. The event payload object emitted contains the following information:
attributes: Object (Please see the on method discussion above)
data: Event Data Object (See Event Map Table above)
date: Date - event date
id: string - event ID
timestamp: int - event date in milliseconds
type: Event Type (See Event Map Table above)
Immutability: With the exception of attributes and date, immutability is maintained on all properties of the event payload. The date property is a native Date instance object. The attributes property is presented to the user exactly as defined by the user.
Every subscribed event listener is assigned a unique event ID during subscription. The on and once methods constitute the two avenues for event subscription. These methods return the unique event ID correspondingly. While the listener function reference remains the most popular means for identifying events for cancellation, the event ID is the surest means of accomplishing same purpose. Please see the off and offById methods.
ISC
FAQs
A timed map javascript data structure ideal for app level caching and memoization.
The npm package @webkrafters/timed-map receives a total of 62 weekly downloads. As such, @webkrafters/timed-map popularity was classified as not popular.
We found that @webkrafters/timed-map demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.