npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

component-lru-cache

v0.0.2

Published

A Browser cache object that deletes the least-recently-used items. and use [localforage](https://github.com/mozilla/localForage) as storage.

Downloads

4

Readme

lru cache

A Browser cache object that deletes the least-recently-used items. and use localforage as storage.

The code is forked and adapted from node-lru-cache

warning version 0.1.* has an async api and use mozilla localforage to store cache objects if you want a sync version that use localstorage use version 0.0.x

Usage:

var LRU = require("lru-cache")
  , options = {ns: 'cache-1', max: 500, maxAge: 1000 * 60 * 60 }
  , cache = LRU(options)
  , otherCache = LRU(50) // sets just the max size


// load cache from storage
cache.load().then(function({
  // cache is loaded
})

// ...

// get an oject from the cache
cache.get('key-1').then(function(v) {
  // do something with value
})

// ...

// save an oject into the cache
cache.set('key-2', { foo: 'bar' }).then(function() {
  // cache is saved
})

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.

Options

  • max The maximum size of the cache, an item size is the length of its key and the stringify length of its value. if no size is specified the cache will keep adding items until the max size of the localstorage is reached.
  • maxAge Maximum age in ms. Items are not pro-actively pruned out as they age, but if you try to get an item that is too old, it'll drop it and return undefined instead of giving it to you.

API

get

update the "recently used"-ness of the key, and returns a promise of the key value.

value

Type: String

return

Type: Promise

set

save value and update the "recently used"-ness of the key

key

Type: String

value

Type: Object

return

Type: Promise

peek

Returns a promise of the key value without updating the "recently used"-ness of the key.

value

Type: String

return

Type: Promise

del

Deletes a key out of the cache.

value

Type: String

reset

Clear the cache entirely, throwing away all values.

return

Type: Promise a Promise that resolve when the change have been saved to storage.

has

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

value

Type: String

return

Type: Boolean

keys

Return an array of the keys in the cache.

return

Type: Array