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

@24hr/rawb-content-cache

v0.9.2

Published

A utlity to keep cached data from a rawb-content service and keep the data up to date by redis events

Downloads

51

Readme

RAWB Content Cache

This module keeps cached content from a fetch and subscrobes to events on a RAWB Content Service so it can refetch when athe correct content is updated at the source.

Example

const ContentClient = require('@24hr/rawb-content-cache');

const config = require('../config');
const logger = require('../logger');

const client = ContentClient({

    // This can be an internal url as in docker-compose or an external url. 
    // It can also contain a port. The content service will by defautl expose internally the default redis port.
    redisUrl: 'redis://url.to.your.service', 

    // The role of this server, since the content service can be run as both draft and live, we need to know which is targeted
    role: config.ROLE,

    // [optional] A logger, like winston. If none is provided, it will fallback to console.log and console.error
    logger,

    // [optional] An api token, that will be used as Bearer, if needed
    apiToken: config.API_TOKEN,

});

// The first parameter is the siteId, which is needed as part of the request in the content service since it might provide data for several sites.
// The second parameter is the resource key.
// The third parameter is the url to fetch the resource. This is typically just the url of the content service with the key, 
// but in some cases it might go trough something else. 
const response = await client.fetch('foo', '/mycoolresource', 'http://your.content.service.com/foo');

console.log(response);

In the example above, upon ffetching the data the first time, the content cache module will begin to listen to a redis event for that resource. When it gets a signal, it will re-fetch the resource with the resource url (third parameter).

fetch and subscribe

The example above showed the fetch function. The client will also expose a function called subcribe that is a little more barebone:

client.subscribe('foo', '/mycoolresource', (data) => {
    console.log('documentType', data.documentType);
    console.log('hash', data.hash);
    console.log('resource', data.resource);
    console.log('externalId', data.externalId);
});

The subscribe function will not fetch anything for you, but will register the callback so you can fetch what you need. It will not provide you with the content either, just the reference to it.

History

  • 0.8.3 [2019-09-08] : Updated docs again
  • 0.8.2 [2019-09-08] : Updated docs again
  • 0.8.1 [2019-09-08] : Updated docs
  • 0.8.0 [2019-09-08] : Refactored version with exposed fetch and subcribe after creating a client
  • 0.7.0 [2019-09-07] : First functional working