Coder Social home page Coder Social logo

lrucache's Introduction

LRUCache

LRU Cache for node.js/browser.

NPM version Build Status Downloads

使用链表实现的 LRU 缓存。getsetupdate 方法会更新 LRU 优先级。

Install

Node.js:

npm install lrucache

bower:

bower install lrucache

Browser:

<script src="/pathTo/lrucache.js"></script>

API

const LRUCache = require('lrucache')

Class LRUCache([capacity])

  • capacity: : Optional, Type: Number, Default: Number.MAX_SAFE_INTEGER.
const cache = LRUCache(100)

LRUCache.prototype.get(key)

Return value.

let a = cache.get('a')

LRUCache.prototype.set(key, value)

Return this.

cache.set('a', [1, 2, 3])

LRUCache.prototype.update(key, fn)

Return this, It only run when key exists.

cache.update('a', function (a) {
  a.push(4)
  return a
})

LRUCache.prototype.remove(key)

Return this.

cache.remove('a')

LRUCache.prototype.removeAll(key)

Return this.

cache.removeAll()

LRUCache.prototype.keys()

Return a array of keys.

cache.keys()

LRUCache.prototype.has(key)

Return true or false.

cache.has('a')

LRUCache.prototype.staleKey()

Return the stalest key or null.

let staleKey = cache.staleKey()

LRUCache.prototype.popStale()

Return the stalest data or null.

let staleDate = cache.popStale()

LRUCache.prototype.info()

Return info.

cache.info()

lrucache's People

Contributors

zensh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.