Skip to content

Commit

Permalink
feat: add BYPASS cache state (#78)
Browse files Browse the repository at this point in the history
* chore: use @keyvhq/core instead of keyv

* chore: add BYPASS cache state

* ci: use github actions

* chore: remove keyv dependency
  • Loading branch information
Kikobeats authored Aug 3, 2021
1 parent 7f0daba commit e6bf8d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: lts/*
- name: Install
run: npm install --no-package-lock
- name: Test
run: npm test
- name: Report
run: mkdir -p coverage && npx nyc report --reporter=text-lcov > coverage/lcov.info
- name: Coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Release
if: ${{ github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'chore(release):') && !startsWith(github.event.head_commit.message, 'docs:') }}
shell: 'script -q -e -c "bash {0}"'
env:
CONVENTIONAL_GITHUB_RELEASER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
git config --global user.email ${{ secrets.GIT_EMAIL }}
git config --global user.name ${{ secrets.GIT_USERNAME }}
npm run release
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# cacheable-response

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

Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const createCompress = require('compress-brotli')
const normalizeUrl = require('normalize-url')
const { parse } = require('querystring')
const prettyMs = require('pretty-ms')
const Keyv = require('@keyvhq/core')
const assert = require('assert')
const getEtag = require('etag')
const { URL } = require('url')
const Keyv = require('keyv')

const isEmpty = value =>
value === undefined ||
Expand Down Expand Up @@ -42,7 +42,10 @@ const createSetHeaders = ({ revalidate }) => {
}

res.setHeader('Cache-Control', cacheControl)
res.setHeader('X-Cache-Status', isHit ? 'HIT' : 'MISS')
res.setHeader(
'X-Cache-Status',
isHit ? 'HIT' : hasForce ? 'BYPASS' : 'MISS'
)
res.setHeader('X-Cache-Expired-At', prettyMs(diff))
res.setHeader('ETag', etag)
}
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"ssr"
],
"dependencies": {
"@keyvhq/core": "~1.1.1",
"compress-brotli": "~1.3.0",
"debug-logfmt": "~1.0.4",
"etag": "~1.8.1",
"keyv": "~4.0.3",
"normalize-url": "~6.1.0",
"pretty-ms": "~7.0.1"
},
Expand All @@ -67,10 +67,8 @@
"ava": "latest",
"ci-publish": "latest",
"conventional-github-releaser": "latest",
"coveralls": "latest",
"finepack": "latest",
"git-authors-cli": "latest",
"git-dirty": "latest",
"got": "latest",
"lint-staged": "latest",
"micro": "latest",
Expand All @@ -93,7 +91,6 @@
"scripts": {
"clean": "rm -rf node_modules",
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "standard-markdown README.md && standard",
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
"prerelease": "npm run update:check && npm run contributors",
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { AssertionError } = require('assert')

const listen = require('test-listen')
const Keyv = require('@keyvhq/core')
const micro = require('micro')
const Keyv = require('keyv')
const test = require('ava')
const got = require('got')

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

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

Expand Down

0 comments on commit e6bf8d6

Please sign in to comment.