@ajayyy/lru-diskcache
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

lru-diskcache

Modified from GitbookIO and ironflytech lru-diskcache to fix npm audit issues.

This also adds type definitions to be used in typescript.

https://www.npmjs.com/package/@ajayyy/lru-diskcache

A disk cache object that deletes the least-recently-used items. Based on lru-cache.

Usage

var LRU = require("lru-diskcache")

var cache = new LRU('./cache', {
    max: 50
});

cache.init()

cache.set("myfile.md", "A string content")
cache.get("file").then(function() { ... }) // Buffer("A string content")

// with a buffer or stream
cache.set("image.png", new Buffer([ ... ]))
cache.set("index.html", request.get("https://www.google.fr"))

cache.reset()    // empty the cache

If you put more stuff in it, then items will fall out.

If you try to put an oversized thing in it, then it'll fall out right away.

API

// Initialize the cache
cache.init()

// Get content as a buffer (return a promise)
cache.get(key)

// Get content as a string
cache.get(key, { encoding: 'utf8' })

// Get content as a stream (return a promise)
cache.getStream(key)

// Check if a key is in the cache, without updating the recent-ness or deleting it for being stale.
cache.has(key)

// Delete a key from the cache
cache.del(key)

// Return total length of objects in cache taking into account
cache.size()

// Manually iterates over the entire cache proactively pruning old entries
cache.prune()

Readme

Keywords

none

Package Sidebar

Install

npm i @ajayyy/lru-diskcache

Weekly Downloads

1

Version

2.1.1

License

Apache-2.0

Unpacked Size

11.9 kB

Total Files

6

Last publish

Collaborators

  • ajayyy