Socket
Socket
Sign inDemoInstall

map-age-cleaner

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    map-age-cleaner

Automatically cleanup expired items in a Map


Version published
Weekly downloads
4.7M
increased by1.89%
Maintainers
1
Install size
12.5 kB
Created
Weekly downloads
 

Package description

What is map-age-cleaner?

The map-age-cleaner npm package is designed to automatically remove expired items from a Map object in JavaScript based on a specified age. This is particularly useful for managing caches or temporary data storage where items should not persist indefinitely. The package works by wrapping a standard Map object and allowing the developer to specify a maximum age for the items. Once an item exceeds this age, it is automatically removed from the Map, helping to manage memory and data relevance efficiently.

What are map-age-cleaner's main functionalities?

Automatic cleanup of expired items

This feature allows for the automatic removal of items from a Map after they have been in the Map for a specified duration. The `maxAge` option is used to define how long (in milliseconds) an item should remain in the Map before being automatically removed.

const mapAgeCleaner = require('map-age-cleaner');
const myMap = new Map();
mapAgeCleaner(myMap, { maxAge: 10000 });
// Adds an item to the map
myMap.set('key', 'value');
// After 10 seconds, the item is automatically removed

Other packages similar to map-age-cleaner

Readme

Source

map-age-cleaner

CI codecov

Automatically cleanup expired items in a Map

Install

$ npm install map-age-cleaner

Usage

import mapAgeCleaner = require('map-age-cleaner');

const map = new Map([
	['unicorn', {data: '🦄', maxAge: Date.now() + 1000}]
]);

mapAgeCleaner(map);

map.has('unicorn');
//=> true

// Wait for 1 second...

map.has('unicorn');
//=> false

Note: Items have to be ordered ascending based on the expiry property. This means that the item which will be expired first, should be in the first position of the Map.

API

mapAgeCleaner(map, [property])

Returns the Map instance.

map

Type: Map

Map instance which should be cleaned up.

property

Type: string
Default: maxAge

Name of the property which olds the expiry timestamp.

  • expiry-map - A Map implementation with expirable items
  • expiry-set - A Set implementation with expirable keys
  • mem - Memoize functions

License

MIT © Sam Verschueren


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 23 Aug 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc