Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hmpo-cached-model

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-cached-model

Cached polling model

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by85.71%
Maintainers
0
Weekly downloads
 
Created
Source

hmpo-cached-model

Cached polling model.

Poll an API at a given interval and save the data to a data storoe such as redis. Multiple nodes can synchronise by sharing the redis instance and key.

Usage

const HmpoCachedModel = require('hmpo-cached-model');

let redisFactory = {
    getClient() {
        return redisInstance;
    }
}

let model = new HmpoCachedModel(
    { // optional seed data
        foo: 'bar',
        boo: 'baz'
    },
    { // options
        url: 'http://example.com/api',
        key: 'root-key',
        store: redisFactory,
        storeInterval: 1000,
        apiInterval: 2000
    }
);

// start polling
model.start();


let data = model.get('data');


// stop polling
countriesLib.stop();

If the API returns an object, all keys are saved to the model, otherwise the data from the API is saved to the data key.

Extend and override parse() to change the way the incomming data from the API is processed.

Upgrading

The deprecated request library has been replaced with got in hmpo-model. The new got library doesn't automativally use the proxy environment variables so you would need to use something like global-agent in your app if you need to specify proxies by environment arguments.

FAQs

Package last updated on 21 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc