Skip to content

A simple LRUCache with maxAge and allowStale options.

License

neumatter/lru-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRUCache

JavaScript Style Guide

A simple LRUCache with maxAge and allowStale options.


Table of Contents


Install

npm i @neumatter/lru-cache

Usage

LRUCache:

import LRUCache from '@neumatter/lru-cache'

type LRUCacheOptions = {
  maxSize?: number,
  maxAge?: number,
  allowStale?: boolean,
  sizeCalculation?: (value: any, key: any) => number,
  notFoundReturnValue?: any
}

// All Options set to default
const cache = new LRUCache({
  maxSize: 1e4,
  maxAge: Infinity,
  allowStale: false
  sizeCalculation: (value, key) => 1,
  notFoundReturnValue: undefined
})

LRUCache.get:

// All Options set to default
const value = cache.get('/key', { allowStale: false }) // returns value or cache.notFoundReturnValue

LRUCache.peek:

Same as LRUCache.get but it doesn't change the order of the entries.

// All Options set to default
const value = cache.peek('/key', { allowStale: false }) // returns value or cache.notFoundReturnValue

LRUCache.set:

cache.set('/key', 99)

LRUCache.clear:

cache.clear()

LRUCache.delete:

const isDeleted = cache.delete('/key') // returns boolean

About

A simple LRUCache with maxAge and allowStale options.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published