Giter Club home page Giter Club logo

map-lru's Introduction

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

map-lru's People

Contributors

commenthol avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.