New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simple-request-caching

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-request-caching

A very simple caching approach for requests.

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
2
Created
Source

simple-request-caching Build Status

A very simple caching approach for requests.

install

There are no external dependencies for the code, so feel free to copy+paste it into whatever framework you are using (e.g., here's an Angular example). Otherwise, install using:

npm install simple-request-caching

using

The basic setup is this:

var CachedRequest = require('simple-request-caching')

var request = new CachedRequest({
	cacheMillis: 500, // the millis that the request is cached, or -1 for forever
	request: function(params) {
		return http.get('/url/path', params)
	}
})

Set a single one of those up for any request you want to cache, then use it like:

request({ key: 'value' }).then(function(data) {
	// the response from the http.get(), as a promise
})

api

When you make a new CachedRequest, it has the following parameters:

  • cacheMillis (required): The number of milliseconds to cache the request response. Use -1 to cache things forever.
  • request (required): The function called when a request is not cached. Must return a promise. Rejected promises are not cached.
  • stringify (optional): A function that is called to stringify the request parameters. If unspecified, a default is used which will stringify flat object correctly and efficiently. If you have deeper objects, you'll want to implement your own stringify function.

license

VOL

Keywords

cache

FAQs

Package last updated on 07 Aug 2016

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