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

makestatic-http-cache

v1.1.10

Published

Caching HTTP client

Downloads

12

Readme

HTTP Cache

Caches HTTP requests

Caches HTTP requests to disc for faster builds.



Install

yarn add makestatic-http-cache

API

HttpCache

Caches HTTP requests to disc so that plugins that make network requests are faster on consecutive builds.

This plugin is automatically available when using the core-standard library.

See Also

HttpCache

new HttpCache(context, options)

Create an HttpCache plugin.

Configure this plugin for the build phase.

Assigns this plugin instance to context.agent and does nothing else until the public functions are invoked by other plugins.

If no directory is given files are cached in the cache folder within this package.

This implementation will only cache responses for the 200 status code, you can cache responses for other status codes using the codes option.

To disable caching you can set the expires option to zero. If the context option cache has been set to false the expires value is forced to zero and the cache is bypassed.

This implementation respects the ETag header and will only use a cached resource when the ETag has not changed.

If a server sends a Cache-Control header containing no-store the response is not cached.

If a server sends a Cache-Control header with a max-age value it is respected and overrides the expires option.

If a Cache-Control header does not contain the no-store value and the server response has not expired the result is served from the cache with no network request (optimal path).

For each request a directory is created corresponding to the request URL in the cache directory. Within each directory a meta.json file is written containing information about the last request, for methods other than HEAD a body file is also written to the directory containing the response body buffer.

  • context Object the processing context.
  • options Object plugin options.
Options
  • directory String the directory used to cache requests.
  • expires Number=86400 number of seconds before a cache expires.
  • codes Array list of HTTP status codes that are cacheable.

.request

HttpCache.prototype.request(url, options[, cb])

Perform a request and cache the result.

If a result already exists in the cache and is not stale the cached result is returned.

Options are passed to the http.request() or https.request() functions depending upon the URL, see the relevant nodejs documentation for more information. Options related to the URL are automatically set by calling require('url').parse(url) so you do not need to assign those options.

If the buffer option is set to false then the response body data is not read which is useful if you either just want the headers for a method other than HEAD or if you are reading in the body data when consuming the response (for example to calculate checksums).

The response object that the promise resolves to will contain meta information about the last request and a body field which is the buffer content from the last request.

The field hit indicates whether the result is coming from the cache or from a network request. It will be false when coming from the network.

When the cb callback function is specified it is invoked with the server response object.

Returns a promise that resolves to the downloaded or cached content.

  • url String the URL to fetch.
  • options Object request options.
  • cb Function callback function.

.head

HttpCache.prototype.head(url[, options][, cb])

Perform a HEAD request and cache the result meta data only.

Returns a promise that resolves to the downloaded or cached content.

  • url String the URL to fetch.
  • options Object request options.
  • cb Function callback function.

.get

HttpCache.prototype.get(url[, options][, cb])

Perform a GET request and cache the result meta data and response buffer.

Returns a promise that resolves to the downloaded or cached content.

  • url String the URL to fetch.
  • options Object request options.
  • cb Function callback function.

.post

HttpCache.prototype.post(url[, options][, cb])

Perform a POST request and cache the result meta data and response buffer.

If you add a data field to the options it is sent as the POST data.

Returns a promise that resolves to the downloaded or cached content.

  • url String the URL to fetch.
  • options Object request options.
  • cb Function callback function.

License

MIT


Created by mkdoc on March 13, 2017