1. map-age-cleaner
Automatically cleanup expired items in a Map
map-age-cleaner
Package: map-age-cleaner
Created by: SamVerschueren
Last modified: Sun, 08 May 2022 19:05:08 GMT
Version: 0.2.0
License: MIT
Downloads: 19,259,026
Repository: https://github.com/SamVerschueren/map-age-cleaner

Install

npm install map-age-cleaner
yarn add map-age-cleaner

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.

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code