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

@koopjs/cache-redis

v1.0.3

Published

Redis Cache Plugin for Koop

Downloads

52

Readme

Koop Redis Cache

Build Status Greenkeeper badge

Usage

To use this cache: First: npm install @koopjs/cache-redis Then: configure your host. In your config file

config/production.json

{
  "cache": {
    "redis": {
      "host": "redis://localhost:6379"
    }
  }
}

If using environment variables like config/custom-environment-variables.json

{
  "cache": {
    "redis": {
      "host": "KOOP_REDIS_HOST"
    }
  }
}

Then you must export the REDIS_HOST variable into your ENV e.g. export KOOP_REDIS_HOST="redis://localhost:6379"

Then require and register the redis cache with Koop

const Koop = require('koop')
const koop = new Koop()
const config = require('config')
const cache = require('@koopjs/cache-redis')
koop.register(cache)

Cache API

insert

Insert geojson into the cache

Note: A metadata entry will be created automatically. It can be populated from an object on the inserted geojson.

const geojson = {
  type: 'FeatureCollection',
  features: [],
  metadata: { // Metadata is an arbitrary object that will be stored in the catalog under the same key as the geojson
    name: 'Example GeoJSON',
    description: 'This is geojson that will be stored in the cache'
  }
}

const options = {
  ttl: 1000 // The TTL option is measured in seconds, it will be used to set the `expires` field in the catalog entry
}

cache.insert('key', geojson, options, err => {
  // This function will call back with an error if there is already data in the cache using the same key
})

append

Add features to an existing geojson feature collection in the cache Note:

const geojson = {
  type: 'FeatureCollection',
  features: []
}
cache.append('key', geojson, err => {
  // This function will call back with an error if the cache key does not exist
})

update

Update a cached feature collection with new features. This will completely replace the features that are in the cache, but the metadata doc will remain in the catalog.

const geojson = {
  type: 'FeatureCollection',
  features: []
}

const options = {
  ttl: 1000
}
cache.update('key', geojson, options, err => {
  // This function will call back with an error if the cache key does not exist
})

upsert

Update a cached feature collection with new features or insert if the features are not there.

const geojson = {
  type: 'FeatureCollection',
  features: []
}

const options = {
  ttl: 1000
}

cache.upsert('key', geojson, options, err => {
  // This function will call back with an error if the cache key does not exist
})

retrieve

Retrieve a cached feature collection

const options = {} // For now there are no options on retrieve. This is meant for compatibility with the general cache API
cache.retrieve('key', options, (err, geojson) => {
  /* This function will call back with an error if there is no geojson in the cache
  The geojson returned will contain the metadata document from the catalog
  {
    type: 'FeatureCollection',
    features: [],
    metadata: {}
  }
  */
})

delete

Remove a feature collection from the cache

cache.delete('key', err => {
  // This function will call back with an error if there was nothing to delete
})

createStream

Create a stream of features from the cache

cache.createStream('key', options)
.pipe(/* do something with the stream of geojson features emitted one at a time */)

Catalog API

The catalog stores metadata about items that are in the cache.

catalog.insert

Add an arbitrary metadata document to the cache. Note: This is called automatically by insert

const metadata = {
  name: 'Standalone metadata',
  status: 'Processing',
  description: 'Metadata that is not attached to any other data in the cache'
}

cache.catalog.insert('key', metadata, err => {
  // this function will call back with an error if there is already a metadata document using the same key
})

catalog.update

Update a metadata entry

const original = {
  name: 'Doc',
  status: 'Processing'
}
cache.catalog.insert('key', original)

const update = {
  status: 'Cached'
}

cache.catalog.update('key', update, err => {
  // this function will call back with an error if there is no metadata in the catalog using that key
})

cache.catalog.retrieve('key', (err, metadata) => {
  /*
    Updates are merged into the existing metadata document
    Return value will be:
    {
      name: 'Doc',
      status: 'Cached'
    }
  */
})

catalog.retrieve

Retrieve a metadata entry from the catalog

cache.catalog.retrieve('key', (err, metadata) => {
  // This function will call back with an error if there is no metadata stored under the given key
  // Or else it will call back with the stored metadata doc
})

catalog.delete

Remove a catalog entry from the catalog Note: This cannot be called if data is in the cache under the same key

cache.catalog.delete('key', err => {
  // This function will call back with an error if there is nothing to delete or if there is still data in the cache using the same key
})