
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
http-disk-cache
Advanced tools
An HTTP client that maintains a persistent disk-based cache. This module was written for internal use with Project Atlas but may be of use to others.
npm install http-disk-cache
var cache = new HTTPCache('/cache/root/directory');
cache.getContents('http://example.com/url', function(err, buf, path) {
if (err) {
console.error("Error:", err);
} else {
console.log("Saved", buf.length, "bytes to path", path);
}
};
cache.openReadStream('http://example.com/url', function(err, readStream) {
if (err) { /* handle error */ }
else { readStream.pipe(destination); }
});
Creates an HTTP cache directory which will work out of cacheRoot. The directory is created if it doesn't exist.
Main URL request method for HTTPCache.
url may be a string URL or an object with a url key and any of the following options:
headers: An object of headers to pass along with the requestencoding: If specified, callback will get a String instead of a BufferCallback arguments:
err: Optional error messagecontents: A String if the encoding option was specified, otherwise a Bufferfilename: The path to the contents on disk (contents are always saved to disk regardless of cache expiry)Creates a readable stream for the contents of url.
url may be a string URL or an object with a url key and any of the following options:
headers: An object of headers to pass along with the requestonProgress arguments:
numBytes: Number of bytes read in the last chunk.Callback arguments:
err: Optional error messagestream: A readable stream containing the content of the URLfilename: The path to the contents on disk (contents are always saved to disk regardless of cache expiry)Checks whether url is already in the cache and, if not, fetches and caches it. url may be a string or an object with the same options as openReadStream(). This is used to warm up the cache and is less resource-intensive than the other methods.
onProgress arguments:
numBytes: Number of bytes read in the last chunk.Callback arguments:
err: Optional error messageCalls abort() on any in-progress HTTP requests that may have been initiated by openReadStream() or assertCached(). The callbacks for those methods will get called with an error.
Return a path to a requested URL assuming that it's already been cached.
Options:
absolute: Return an absolute path instead of a path relative to the cache root (default: false)Synchronously set the contents for url. url must begin with cache:. Throws on error.
Synchronously get the contents for url. Throws on error.
url may be a string URL or an object with a url key and any of the following options:
headers: An object of headers to pass along with the requestencoding: If specified, will return a String instead of a BufferReturns a buffer, unless encoding is provided.
reset must be called if you wish to reload any expired assets. (Otherwise, assets always
persist for the lifetime of the cache, even if they would not otherwise be cached at all.)
Iterates over all .meta files in the cache. For each one, the meta data is loaded and parsed,
and the corresponding content file is stated.
shouldCleanCb is then called as shouldCleanCb(curFileNum, totalFiles, metadata, stat, resultCb)
where:
shouldCleanCb).shouldCleanCb should call resultCb with 'REMOVE' to signal that the entry should be removed from the
cache, or 'KEEP' to indicate that the file should be kept.
The on-disk cache is structured as follows:
79/da/646f91932de1ed0267ed1abdb741.meta.A cached object is valid iff:
.meta file contains a valid JSON object.expiry property has not elapsed..meta file as the contentMD5 property.A valid cached object may always be served in response to an openReadStream request.
An invalid cached object may be deleted at any time, and in practice, will be deleted when it
is next accessed while attempting to meet a request.
Fetched resources are always saved to disk regardless of expiry. This is ease integration with things such as SDL functions which load images or dynamic libraries from disk.
Enable debug output by setting the DEBUG environment variable to include http-disk-cache
FAQs
An HTTP client that maintains a persistent disk-based cache
The npm package http-disk-cache receives a total of 3 weekly downloads. As such, http-disk-cache popularity was classified as not popular.
We found that http-disk-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.