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

cacheable-request

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cacheable-request

Wrap native HTTP requests with RFC compliant cache support

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.9M
decreased by-53.48%
Maintainers
1
Weekly downloads
 
Created

What is cacheable-request?

The cacheable-request npm package is a wrapper for the native HTTP/HTTPS request functionality in Node.js, providing an easy-to-use cache layer for repeat requests. It is designed to cache responses based on their Cache-Control header and supports the caching of GET and HEAD requests.

What are cacheable-request's main functionalities?

Caching GET and HEAD requests

This feature allows you to cache GET and HEAD requests. The code sample shows how to create a cacheable request using the cacheable-request package with a custom cache adapter.

const CacheableRequest = require('cacheable-request');
const http = require('http');
const cacheAdapter = require('./some-cache-adapter');

const cacheableRequest = new CacheableRequest(http.request, cacheAdapter);

const req = cacheableRequest('http://example.com', response => {
  // Use the response here
});

req.on('request', request => request.end());

Custom cache adapters

This feature allows the use of custom cache adapters to store and retrieve cached responses. The code sample demonstrates how to use a custom cache adapter with the cacheable-request package.

const CacheableRequest = require('cacheable-request');
const http = require('http');
const myCacheAdapter = {
  get: (key) => { /* custom get implementation */ },
  set: (key, value) => { /* custom set implementation */ }
};

const cacheableRequest = new CacheableRequest(http.request, myCacheAdapter);

HTTP and HTTPS support

The package supports both HTTP and HTTPS protocols. The code sample illustrates how to create a cacheable HTTPS request.

const CacheableRequest = require('cacheable-request');
const https = require('https');
const cacheAdapter = require('./some-cache-adapter');

const cacheableRequest = new CacheableRequest(https.request, cacheAdapter);

const req = cacheableRequest('https://secure.example.com', response => {
  // Use the response here
});

req.on('request', request => request.end());

Other packages similar to cacheable-request

Keywords

FAQs

Package last updated on 13 Aug 2017

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