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

ya-cache

v1.0.1

Published

Yet another cache

Downloads

22

Readme

yet another cache

Why the heck does the world need another caching module? Well, it probably doesn't but while working on http-asset part of me was feeling crazy, part of me was feeling ambitious, and the rest of me was too lazy to sift through all the caching modules on NPM to find the one that best fit the bill.

So, I offer you ya-cache.

features

  • super simple api
  • file system backed
  • cache is just JSON in a file
  • file system locking ¯\_(ツ)_/¯

example

let Cache = require('ya-cache')
let thingCache = new Cache(join(__dirname, '__cache__'))

const HOUR = 1000 * 60 * 60

let [expires, thing] = thingCache.gets('expire', 'thing')
if (expires && expires < Date.now()) {
  thing = await calculateComplexThingy()
  await thingCache.sets({
    expire: Date.now() + 24 * HOUR
    thing: thing
  })
}

doSomethingWithThing(thing)

api


new Cache(path, lockFileOptions = {})

Constructs a cache object, provides the api to each cache


cache.get([key]) -> Promise

Get the value of a key, returns a promise. If the key argument is undefined then all keys and their values are returned in an object.

cache.get('key').then(function (val) {
  console.log('value for key is', val)
})

cache.set(key, val) -> Promise

Set the value of a key, returns a promise.

cache.set('key', 'value').then(function () {
  console.log('value for %s is now set to %s', 'key', 'value')
})

cache.gets(...keys) -> Promise

Get one or more keys, returns a promise that resolves to an array of values.

cache.gets('key1', 'key2', 'key3').then(function (vals) {
  vals.forEach(function (val, i) {
    console.log('key%i has value %s', i + 1, val)
  })
})

cache.sets({ key: value ... }) -> Promise

Set one of more keys, returns a promise that resolves to an object of the saved values.

cache.sets({
  key1: 'foo'
  key2: 'bar'
  key3: 'baz'
}).then(function (vals) {
  console.log('saved vals', vals)
})

cache.clear([key]) -> Promise

Clear a key in the cache. If the key is undefined then all keys are cleared

cache.set('foo', 'bar')
cache.clear('foo')
cache.get('foo').then(function (val) {
  console.log('foo equals "%s"', val) // foo equals "undefined"
})