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: 12 months ago
JSON representation
A very simple cache control middleware for express
- Host: GitHub
- URL: https://github.com/ulisesgascon/simple-cache-control-middleware
- Owner: UlisesGascon
- License: mit
- Created: 2023-03-21T07:43:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T09:10:15.000Z (almost 3 years ago)
- Last Synced: 2024-10-13T04:34:23.550Z (over 1 year ago)
- Topics: cache, cache-control, express, express-middleware
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/simple-cache-control-middleware
- Size: 63.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
simple-cache-control-middleware
A very simple cache control middleware for express
# 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