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

data-point-cache

v4.1.1-alpha.0

Published

DataPoint Cache Layer

Downloads

297

Readme

data-point-cache

Build Status codecov Coverage Status All Contributors

DataPoint cache layer

Factory method to create a simple cache API that you can use for data persistence.

Requirements

  • Node 8 LTS (or higher)
  • Redis (Optional for development)

Install

$ npm install data-point-cache

Usage

const Cache = require('data-point-cache')

Cache.create()
  .then(cache => {
    return cache.set('myKey', 'foo', '20m')
      .then(() => {
        return cache.get('myKey')
      })
  })
  .then(result => {
    console.log('foo')
  )

Storage mechanism

This cache API has an in-memory storage mechanism. The idea here is that every time a get/set operation happens, a short (TTL of 2 seconds) in-memory version of that key will be stored. After the TTL of the in-memory key has expired, the key will be removed. The swiping mechanism triggers every second and will kill every key that has its TTL has expired. The idea behind this is to try to be as optimal with our requests to redis, but also be careful not to store for too long in the in-memory layer.

Like any software, see if this works for you and your use case before going to production.

API

Cache.create

Create a cache instance.

Cache.create({
  localTTL: Number,
  redis: Object,
}):Promise<cache>

This factory method returns a Promise that resolves to a cache instance.

| option | type | required | description | |:---|:---|:---|:---| | localTTL | Number | optional | Value in Milliseconds of in memory TTL, by default is set to 2000 (2 seconds) | | redis | Object | optional | Value passed to the ioredis constructor |

cache.set

Adds a new entry to the cache. This method

cache.set(key:String, value:Any, ttl:String):Promise

Returns a promise.

Parameter description:

arguments:

| argument | type | required | description | |:---|:---|:---|:---| | key | String | yes | key related to this entry. | | value | Any | yes | Value to be stored, this value will be stringified when stored in redis. | | ttl | String | optional | Time To Live of the entry. Defaults to 20 minutes. |

cache.get

This method gets an entry from the cache. Every time this method gets executed it will:

  1. check if it exists in redis
  2. attempt to retrieve it from the in-memory cache
  3. if not found it will try to get it from redis
  4. if found in redis, it will re-store it back into the in-memory cache where it will be available for 2 seconds.
cache.get(key:String):Promise<Any|undefined>

Returns a promise, if the key does not exist it will resolve to undefined.

Parameter description:

arguments:

| argument | type | required | description | |:---|:---|:---|:---| | key | String | yes | key related to this entry. |

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE file for details