Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ulisesgascon/simple-cache-control-middleware

A very simple cache control middleware for express
https://github.com/ulisesgascon/simple-cache-control-middleware

cache cache-control express express-middleware

Last synced: 1 day ago
JSON representation

A very simple cache control middleware for express

Awesome Lists containing this project

README

        



simple-cache-control-middleware


A very simple cache control middleware for express


npm version
license
downloads
Known Vulnerabilities

# About

A very simple cache control middleware for express.

โค๏ธ Awesome Features:

- Easy to define the max-age ๐Ÿ”ฅ
- Only GET Request are cached ๐Ÿบ
- `debug` is supported ๐Ÿ’ช
- Easy to use and great test coverage โœ…

## Usage

### Install

```bash
npm install simple-cache-control-middleware
```

### Default

```js
const express = require('express');
const simpleCacheControlMiddleware = require('simple-cache-control-middleware')
const app = express();

app.use(simpleCacheControlMiddleware())

app.get('/', (req, res) => {
res.send(`This request has 5m max-age`);
});

app.post('/', (req, res) => {
res.send(`This request is not cached`);
});

app.listen(3000, () => {
console.log('We are in port 3000!');
});
```

### Custom max-age

```js
const express = require('express');
const simpleCacheControlMiddleware = require('simple-cache-control-middleware')
const app = express();

const TEN_MINUTES = 60 * 10
app.use(simpleCacheControlMiddleware({
maxAge: TEN_MINUTES
}))
```

## Built With

Development only:

- [Standard](https://www.npmjs.com/package/standard) - Linting
- [Jest](https://www.npmjs.com/package/jest) Testing framework

Production only:

- [debug](https://www.npmjs.com/package/debug) - Debug the app
## Contributing

Please read [CONTRIBUTING.md](https://github.com/UlisesGascon/user-language-middleware/blob/main/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/ulisesGascon/simple-cache-control-middleware/tags).

## Authors

- **Ulises Gascรณn** - *Initial work- - [@ulisesGascon](https://github.com/ulisesGascon)

See also the list of [contributors](https://github.com/ulisesGascon/simple-cache-control-middleware/contributors) who participated in this project.

## License

This project is licensed under the GNU AGPL3.0 License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

Heavily inspired in [RegBrain | Cache headers in Express js app
](https://regbrain.com/article/cache-headers-express-js) post