Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

express-disk-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-disk-cache

Middleware for caching responses sent through [Express](http://expressjs.com/) to disk.

latest
npmnpm
Version
1.1.1
Version published
Weekly downloads
7
-72%
Maintainers
1
Weekly downloads
 
Created
Source

Express disk cache

Middleware for caching responses sent through Express to disk.

Why does this exist?

Because web servers are good at delivering static files. It's also useful if you have NGINX sitting in front of your node.js webserver and want to take some of the load off it.

This also makes cache invalidation quite simple: just delete the file.

Install

Use your package manager of choice, for example:

npm install express-disk-cache

API

Then include the middleware in your Express app:

var cache = require('express-disk-cache');

Example

var app = Express();

// This will cache every response to disk
// assuming it meets the conditions described below
app.use(cache({
  directory: __dirname + '/cache'
}));

How it works

As I understand it, HTTP response in express and node is a writeable stream. It wraps the res.write and res.end functions so it will work no matter how you send the response, using res.send, res.render, res.sendStatus, res.sendFile etc...

Conditions for caching

  • The cache-control header is not set to no-cache
  • There is no query string in the URL
  • There is no session associated with the request

To do

Check that the URL contains valid characters that we can use to create a file on the file system. Re-implement the filter function used by compression.

FAQs

Package last updated on 21 Jan 2021

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