Skip to content

doclify/lru-cache.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache

Least Recently Used cache for browser or Node.js.

Instalation

npm install @doclify/lru-cache

Usage

import LRU from '@doclify/lru-cache'
// commonjs
// const LRU = require('@doclify/lru-cache')

const cache = new LRU({
	max: 1000, //max items in cache
	ttl: 60 * 1000 //max ttl in ms, set 0 for never expiring cache
})

cache.set('foo', 'baz')

const value = cache.get('foo')

Reference

.has(): boolean

Returns whether key exists in cache

.clear()

Clears the cache

.set(key: string, value: any, ttl?: number): boolean

Sets item in cache

.get(key: string)

Returns item from cache

.delete(key: string)

Removes item from cache

.evict(): boolean

Evicts the least recently used item from cache

License

This repository is published under the MIT license.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published