New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-cash

Package Overview
Dependencies
Maintainers
4
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-cash - npm Package Compare versions

Comparing version 2.1.1 to 3.0.0-0

.babelrc

19

package.json
{
"name": "koa-cash",
"description": "HTTP response caching for Koa",
"version": "2.1.1",
"version": "3.0.0-0",
"publishConfig": {
"tag": "next"
},
"dependencies": {

@@ -13,4 +16,8 @@ "bluebird": "^3.1.1",

"devDependencies": {
"istanbul": "^0.4.2",
"koa": "^1.0.0",
"babel-cli": "^6.23.0",
"babel-plugin-transform-async-generator-functions": "^6.22.0",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-register": "^6.23.0",
"istanbul": "^1.1.0-alpha.1",
"koa": "^2.0.0",
"lru-cache": "^4.0.0",

@@ -22,2 +29,4 @@ "mocha": "^3.1.2",

"scripts": {
"build": "babel index.js --out-dir dist",
"prepublish": "npm run build",
"lint": "standard index.js test/**/*.js",

@@ -36,5 +45,3 @@ "test": "NODE_ENV=test mocha",

"license": "MIT",
"files": [
"index.js"
],
"main": "dist/index.js",
"keywords": [

@@ -41,0 +48,0 @@ "koa",

@@ -22,10 +22,10 @@ # Koa Cash

app.use(function* (next) {
app.use(function* (ctx, next) {
// this response is already cashed if `true` is returned,
// so this middleware will automatically serve this response from cache
if (yield this.cashed()) return
if (await ctx.cashed()) return
// set the response body here,
// and the upstream middleware will automatically cache it
this.response.body = 'hello world!'
ctx.response.body = 'hello world!'
})

@@ -42,3 +42,3 @@ ```

Default max age for the cache if not set via `yield this.cashed(maxAge)`.
Default max age for the cache if not set via `await ctx.cashed(maxAge)`.

@@ -54,17 +54,17 @@ #### `threshold`

```js
function hash(_this) {
return this.request.url
function hash(ctx) {
return ctx.request.url
}
```
`this` is the Koa context and is also passed as an argument.
By default, it caches based on the URL.
`ctx` is the Koa context. By default, it caches based on the URL.
#### `get()`
Get a value from a store. Must return a "yieldable", which returns the cache's value, if any.
Get a value from a store. Can be a regular function or an `async` function,
which returns the cache's value, if any.
```js
function get(key, maxAge) {
return <yieldable>
async function get(key, maxAge) {
return <cached-value>
}

@@ -78,7 +78,7 @@ ```

Set a value to a store. Must return a "yieldable".
Set a value to a store. Can be a regular function or an `async` function.
```js
function set(key, value, maxAge) {
return <yieldable>
async function set(key, value, maxAge) {
...
}

@@ -110,6 +110,6 @@ ```

### var cached = yield this.cashed([maxAge])
### var cached = await ctx.cashed([maxAge])
This is how you enable a route to be cached.
If you don't call `yield this.cashed()`,
If you don't call `await ctx.cashed()`,
then this route will not be cached nor will it attempt to serve the request from the cache.

@@ -121,3 +121,3 @@

then the current request has been served from cache and __you should early `return`__.
Otherwise, continue setting `this.response.body=` and this will cache the response.
Otherwise, continue setting `ctx.response.body=` and this will cache the response.

@@ -124,0 +124,0 @@ ## Notes

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc