Socket
Socket
Sign inDemoInstall

cache-or-req

Package Overview
Dependencies
52
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cache-or-req

A very simple cache for request-promise operations, primary goal is to return always a value after the first real fetch. The library tried to re-fetch after TTL is reached but returns immediately, the next request within the TTL time will return the updat


Version published
Weekly downloads
4
increased by33.33%
Maintainers
3
Install size
5.71 MB
Created
Weekly downloads
 

Readme

Source

cache-or-req

A very simple cache for request-promise operations, primary goal is to return always a value after the first real fetch. The library tried to re-fetch after TTL is reached but returns immediately, the next request within the TTL time will return the updated result. This library should primarily be used for accessing configuration via APIs and ensure that services get always some kind of configuration.

This library is a very simple wrapper around request-promise (https://www.npmjs.com/package/request-promise) basic implementation request().then().catch()


Usage

const CacheOrReq = require('./CacheOrReq');

let cacheOrReq = new CacheOrReq(
    1000, // refresh cache in background as soon as the item gets older than one second
    1000 * 60 * 60 // delete cache items as soon as they got older than 1 hour without accessing it
);
cacheOrReq.get({ // request-promise options
    url: TEST_URL,
    method: 'GET'
}).then((data) => {
    // data.lastUpdate = new Date();
    // data.content = response from request
}).catch((error) => {
    // error.lastUpdate = new Date();
    // error.error = raw error from request-promise
});

// to clear cache:
cacheOrReq.clearCache();

FAQs

Last updated on 27 Nov 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc