Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koajs/ctx-cache-control
Augment Koa with ctx.cacheControl(maxAge)
https://github.com/koajs/ctx-cache-control
Last synced: 2 months ago
JSON representation
Augment Koa with ctx.cacheControl(maxAge)
- Host: GitHub
- URL: https://github.com/koajs/ctx-cache-control
- Owner: koajs
- License: mit
- Created: 2016-06-19T03:43:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T02:06:26.000Z (about 2 years ago)
- Last Synced: 2024-04-14T13:08:39.365Z (8 months ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 9
- Watchers: 8
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - ctx-cache-control - Augment Koa with ctx.cacheControl(maxAge) (Middleware)
README
# Koa Context Cache Control
[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![Greenkeeper badge](https://badges.greenkeeper.io/koajs/ctx-cache-control.svg)](https://greenkeeper.io/)
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]Augments Koa with `ctx.cacheControl()` and `ctx.response.cacheControl()`.
## Example
```js
const Koa = require('koa')const app = new Koa()
require('koa-ctx-cache-control')(app)
app.use(async (ctx, next) => {
ctx.cacheControl(false) // no cacheawait next()
})
```## API
### ctx.cacheControl()
If it's a time [ms](https://www.npmjs.com/package/ms) can parse, then it uses that time as the max age:
```js
ctx.cacheControl('1 second') // => max-age=1
```Otherwise, it sets the header directly:
```js
ctx.cacheControl('max-age=0') // => max-age=0
```### ctx.cacheControl(ms)
Sets the max age with a number in milliseconds.
```js
ctx.cacheControl(1000) // => max-age=1
```### ctx.cacheControl(false)
Sets a no cache directive.
[npm-image]: https://img.shields.io/npm/v/koa-ctx-cache-control.svg?style=flat-square
[npm-url]: https://npmjs.org/package/koa-ctx-cache-control
[travis-image]: https://img.shields.io/travis/koajs/ctx-cache-control/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/koajs/ctx-cache-control
[codecov-image]: https://img.shields.io/codecov/c/github/koajs/ctx-cache-control/master.svg?style=flat-square
[codecov-url]: https://codecov.io/github/koajs/ctx-cache-control
[david-image]: http://img.shields.io/david/koajs/ctx-cache-control.svg?style=flat-square
[david-url]: https://david-dm.org/koajs/ctx-cache-control
[license-image]: http://img.shields.io/npm/l/koa-ctx-cache-control.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/koa-ctx-cache-control.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/koa-ctx-cache-control