Giter Site home page Giter Site logo

lru-cache's Introduction

build status

LRU Cache

LRU Cache is a dead simple implementation of, you guessed it, an LRU cache. If you're looking for a LRU cache with plenty of features, this is not the library you're looking for /end jedi mind trick.

Download

Usage

API

LruCache(maxSize)

The constructor function. maxSize is the number of entries the cache will hold before it starts evicting. maxSize defaults to 100.

LruCache#set(key, entry)

Store an entry in the cache. key is expected to be a string and entry can be anything, note however it'll be stored by reference.

LruCache#get(key)

Retrieves a stored entry from the cache. If the entry doesn't exist, undefined will be returned.

Example

var cache = new LruCache(3);

cache.set('one', 1);
cache.set('two', 2);
cache.set('three', 3);
cache.get('one');
cache.set('four', 4);

cache.get('one') === 1;
cache.get('two') === undefined;
cache.get('three') === 3;
cache.get('four') === 4;

Testing

Tests are written using Jasmine and ran with Karma. To run LRU Cache's test suite with PhantomJS, run npm test.

Issues

Found a bug? Create an issue on GitHub.

https://github.com/jharding/lru-cache/issues

Versioning

For transparency and insight into the release cycle, releases will be numbered with the follow format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

License

Copyright (c) 2013 Jake Harding
Licensed under the MIT License.

lru-cache's People

Contributors

jharding avatar

Stargazers

Xiaolei Yu avatar Jonathan Yee avatar

Watchers

 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.