Giter Site home page Giter Site logo

exbotanical / tenure Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 385 KB

Manageable LRU in-memory cache instance for fast lookups and configurable eviction policies

Home Page: https://www.npmjs.com/package/tenure

License: MIT License

JavaScript 100.00%
cache-replacement cache-policy lru-cache lru-replacement-algorithm doubly-linked-list in-memory-caching hashmap

tenure's Introduction

Build Status npm version License: MIT

Tenure | Manageable LRU caching

Tenure is a manageable LRU cache instance that uses hashmap lookups and an Open Doubly Linked List to enact the Least-Recently Used algorithm

Algorithm

LRU Cache Algorithm

Installation

npm install tenure

OR

yarn add tenure

Supported Environments

Tenure currently supports UMD, CommonJS (node versions >= 10), and ESM build-targets

API Reference


LruCache


new LruCache(capacity, cb)

Implements a canonical Least Recently-Used Cache

Param Type Description
capacity number The maximum capacity (items) of the cache; beyond this threshold, the eviction policy is enacted. Defaults to 10
cb function Optional callback to be invoked upon each eviction; called with evicted item key, value


lruCache.get(key) ⇒ any | null

Retrieve an item from the cache; if extant, the item will be designated 'most-recently used' Returns: any | null - The retrieved value, if extant; else, null

Param Type
key any


lruCache.put(key, value) ⇒ boolean

Add or update a given key / value pair in the cache

Put transactions will move the key to the head of the cache, designating it as 'most recently-used'

If the cache has reached the specified capacity, Put transactions will also enact the eviction policy, thereby removing the least recently-used item Returns: boolean - A boolean indicating whether an eviction occurred

Param Type
key any
value any


lruCache.del(key) ⇒ boolean

Remove an item corresponding to a given key from the cache, if extant Returns: boolean - A boolean indicating whether of not the delete transaction occurred

Param Type
key any


lruCache.keys() ⇒ array

Returns: array - An array of all keys currently extant in the cache


lruCache.has(key) ⇒

Verify the existence of a key in the cache without enacting the eviction policy Returns: A boolean flag verifying the existence (or lack thereof) of a given key in the cache

Param Type
key any


lruCache.lru() ⇒ array | null

Returns: array | null - the least recently-used key / value pair, or null if not extant


lruCache.drop()

Drop all items from the cache, effectively purging it


lruCache.resize(cap) ⇒ number

Resizes the cache capacity.

Invoking this transaction will evict all least recently-used items to adjust the cache, where necessary Returns: number - the number of evictions enacted

Param Type Description
cap number new capacity


lruCache.size() ⇒ number

Returns: number - the current size of the cache


lruCache.capacity() ⇒ number

Returns: number - the current maximum buffer capacity of the cache

tenure's People

Contributors

exbotanical 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.