Skip to content

Commit e6bf8d6

Browse files
authored
feat: add BYPASS cache state (#78)
* chore: use @keyvhq/core instead of keyv * chore: add BYPASS cache state * ci: use github actions * chore: remove keyv dependency
1 parent 7f0daba commit e6bf8d6

6 files changed

Lines changed: 48 additions & 38 deletions

File tree

.github/workflows/main.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: lts/*
21+
- name: Install
22+
run: npm install --no-package-lock
23+
- name: Test
24+
run: npm test
25+
- name: Report
26+
run: mkdir -p coverage && npx nyc report --reporter=text-lcov > coverage/lcov.info
27+
- name: Coverage
28+
uses: coverallsapp/github-action@master
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
- name: Release
32+
if: ${{ github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'chore(release):') && !startsWith(github.event.head_commit.message, 'docs:') }}
33+
shell: 'script -q -e -c "bash {0}"'
34+
env:
35+
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
37+
run: |
38+
git config --global user.email ${{ secrets.GIT_EMAIL }}
39+
git config --global user.name ${{ secrets.GIT_USERNAME }}
40+
npm run release

.travis.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# cacheable-response
22

33
![Last version](https://img.shields.io/github/tag/Kikobeats/cacheable-response.svg?style=flat-square)
4-
[![Build Status](https://img.shields.io/travis/Kikobeats/cacheable-response/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/cacheable-response)
54
[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/cacheable-response.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/cacheable-response)
65
[![NPM Status](https://img.shields.io/npm/dm/cacheable-response.svg?style=flat-square)](https://www.npmjs.org/package/cacheable-response)
76

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const createCompress = require('compress-brotli')
55
const normalizeUrl = require('normalize-url')
66
const { parse } = require('querystring')
77
const prettyMs = require('pretty-ms')
8+
const Keyv = require('@keyvhq/core')
89
const assert = require('assert')
910
const getEtag = require('etag')
1011
const { URL } = require('url')
11-
const Keyv = require('keyv')
1212

1313
const isEmpty = value =>
1414
value === undefined ||
@@ -42,7 +42,10 @@ const createSetHeaders = ({ revalidate }) => {
4242
}
4343

4444
res.setHeader('Cache-Control', cacheControl)
45-
res.setHeader('X-Cache-Status', isHit ? 'HIT' : 'MISS')
45+
res.setHeader(
46+
'X-Cache-Status',
47+
isHit ? 'HIT' : hasForce ? 'BYPASS' : 'MISS'
48+
)
4649
res.setHeader('X-Cache-Expired-At', prettyMs(diff))
4750
res.setHeader('ETag', etag)
4851
}

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
"ssr"
5555
],
5656
"dependencies": {
57+
"@keyvhq/core": "~1.1.1",
5758
"compress-brotli": "~1.3.0",
5859
"debug-logfmt": "~1.0.4",
5960
"etag": "~1.8.1",
60-
"keyv": "~4.0.3",
6161
"normalize-url": "~6.1.0",
6262
"pretty-ms": "~7.0.1"
6363
},
@@ -67,10 +67,8 @@
6767
"ava": "latest",
6868
"ci-publish": "latest",
6969
"conventional-github-releaser": "latest",
70-
"coveralls": "latest",
7170
"finepack": "latest",
7271
"git-authors-cli": "latest",
73-
"git-dirty": "latest",
7472
"got": "latest",
7573
"lint-staged": "latest",
7674
"micro": "latest",
@@ -93,7 +91,6 @@
9391
"scripts": {
9492
"clean": "rm -rf node_modules",
9593
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
96-
"coverage": "nyc report --reporter=text-lcov | coveralls",
9794
"lint": "standard-markdown README.md && standard",
9895
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
9996
"prerelease": "npm run update:check && npm run contributors",

test/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const { AssertionError } = require('assert')
22

33
const listen = require('test-listen')
4+
const Keyv = require('@keyvhq/core')
45
const micro = require('micro')
5-
const Keyv = require('keyv')
66
const test = require('ava')
77
const got = require('got')
88

@@ -193,7 +193,7 @@ test('force query params to invalidate', async t => {
193193
t.is(headersTwo['x-cache-status'], 'HIT')
194194

195195
const { headers: headersThree } = await got(`${url}/kikobeats?force=true`)
196-
t.is(headersThree['x-cache-status'], 'MISS')
196+
t.is(headersThree['x-cache-status'], 'BYPASS')
197197
t.is(headersThree['x-cache-expired-at'], '0ms')
198198
// t.snapshot(parseCacheControl(headersThree))
199199

0 commit comments

Comments
 (0)