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

rrcache

v0.2.2

Published

Random Replacement Cache with TTL and preload option. A simple and clean RR cache that just works.

Downloads

14

Readme

rrcache

Random Replacement Cache with TTL and preload option. A simple and clean RR cache that just works.

See Cache Types for a comparison of different cache algorithms

install

npm i rrcache

usage

var defaultOptions = { max: 100000 } // max entries
var rrcache = require('rrcache')(defaultOptions)

get(key) => value

value = rrcache.get('keyvalue')

set(key, value[, ttl])

optional ttl (time to live)

setting a key without a ttl will clear any current timeout

rrcache.set('project', 'rrcache') // will automatically make room

or

rrcache.set('mykey', 'myvalue', 60000) // expire key in 60 seconds

clear()

clear the cache

rrcache.clear()

options(newOptions)

change the cache options, currently only can change the max threshold. If the max cache size is decreased, the cache will automatically clean the cache to the new size. max = 0 disables the RR cleaning of the cache.

rrcache.options({max: 0}) // disable cache

length()

return the number of entries in the cache

var currentEntries = rrcache.length()

values()

return the current key/values of the cache

rrcache.set('firstbase', 'jon')
rrcache.set('secondbase', 'joe')

var values = rrcache.values()
console.log(values)
{
   "firstbase": "jon",
   "secondbase": "joe"
}

or persist the cache values for later

fs = require('fs')
fs.writeFileSync('mycache.json', JSON.stringify(rrcache.values()))

load(values)

manually load the cache with a set of values

fs = require('fs')
rrcache.load(JSON.parse(fs.readFileSync('mycache.json')))

loadFile()

rrcache.loadFile('mycache.json')

saveFile()

rrcache.saveFile('mycache.json')
// or if previous loadFile
rrcache.saveFile()

preload the cache with a set of values

fs              = require('fs')
var initialData = JSON.parse(fs.readFileSync('mycache.json'))
var rrcache     = require('rrcache')({ data: initialData }) // preload cache

reload the cache during init

var rrcache = require('rrcache')({ file: 'mycache.json', max: 1000000})

multiple cache instances

var RRCache = require('rrcache')
var cache1  = new RRCache()
var cache2  = new RRCache()

License: MIT