Skip to content

"Least Recently Used" (LRU) cache compatible to ES6 Map

License

Notifications You must be signed in to change notification settings

commenthol/map-lru

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MapLRU

"Least Recently Used" (LRU) cache compatible to ES6 Map

NPM version Build Status Coverage Status

Useful for caching with limited memory usage. API compatible with built-in Map object.

Install

$ npm install map-lru

Usage

import MapLRU from 'map-lru' // ES5
// const MapLRU = require('map-lru') // commonJs
const cache = new MapLRU(10)

cache.set('♥', '♥♥♥')

cache.has('♥');
//=> true
cache.get('♥');
//=> '♥♥♥'
cache.last
//=> '♥'
cache.size
//=> 1

API

new MapLRU(maxSize)

Creates a new instance

Parameters

  • maxSize Number max. size of the LRU cache.

Additional methods

  • last

    Returns the last accessed key.

    Returns Any

  • peek(key)

    Get an item without marking it as recently used.

    Parameters

    • key Any
  • keysAccessed()

    keys in order of access - last one is most recently used one.

    Returns Iterator Iterator object


Default Map methods

License

Unlicense