Skip to content

Commit 5c7aade

Browse files
authored
Merge pull request #17 from fastify/next
Prepare fastify-caching master for v2
2 parents 6731626 + 242218d commit 5c7aade

File tree

8 files changed

+54
-24
lines changed

8 files changed

+54
-24
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ profile-*
4545

4646
# VS Code
4747
.vscode/
48+
49+
# lock files
50+
package-lock.json
51+
yarn.lock

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: node_js
22

33
node_js:
4-
- "9"
4+
- "11"
5+
- "10"
56
- "8"
67
- "6"
78

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 James Sumners <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# fastify-caching
22

3+
[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-caching.svg)](https://greenkeeper.io/) [![Build Status](https://travis-ci.org/fastify/fastify-caching.svg?branch=master)](https://travis-ci.org/fastify/fastify-caching)
4+
35
*fastify-caching* is a plugin for the [Fastify](http://fastify.io/) framework
46
that provides mechanisms for manipulating HTTP cache headers according to
5-
[RFC 2616 §14.9](https://tools.ietf.org/html/rfc2616#section-14.9).
7+
[RFC 2616 §14.9](https://tools.ietf.org/html/rfc2616#section-14.9).
8+
9+
Supports Fastify versions ^1.0.0.
610

711
This plugin fully supports Fastify's encapsulation. Therefore, routes that
812
should have differing cache settings should be registered within different

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "A plugin for Fastify to enable management of cache control headers",
55
"main": "plugin.js",
66
"scripts": {
7-
"test": "tap 'test/**/*.test.js'",
8-
"test-ci": "tap --cov 'test/**/*.test.js'",
9-
"lint": "standard | snazzy",
7+
"test": "tap test/*.test.js",
8+
"test-ci": "tap --cov test/*.test.js",
9+
"lint": "standard --verbose | snazzy",
1010
"lint-ci": "standard"
1111
},
1212
"precommit": [
@@ -29,15 +29,15 @@
2929
},
3030
"homepage": "https://github.com/fastify/fastify-caching#readme",
3131
"devDependencies": {
32-
"fastify": "^1.1.0",
32+
"fastify": "^1.13.0",
3333
"pre-commit": "^1.2.2",
34-
"snazzy": "^7.1.1",
35-
"standard": "^11.0.0",
36-
"tap": "^11.1.1"
34+
"snazzy": "^8.0.0",
35+
"standard": "^12.0.1",
36+
"tap": "^12.1.0"
3737
},
3838
"dependencies": {
3939
"abstract-cache": "^1.0.1",
40-
"fastify-plugin": "^0.2.2",
40+
"fastify-plugin": "^1.2.1",
4141
"uid-safe": "^2.1.5"
4242
}
4343
}

plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function etag (value, lifetime) {
3030
function etagHandleRequest (req, res, next) {
3131
if (!req.headers['if-none-match']) return next()
3232
const etag = req.headers['if-none-match']
33-
this.cache.get({id: etag, segment: this.cacheSegment}, (err, cached) => {
33+
this.cache.get({ id: etag, segment: this.cacheSegment }, (err, cached) => {
3434
if (err) return next(err)
3535
if (cached && cached.item) {
3636
res.statusCode = 304
@@ -44,7 +44,7 @@ function etagOnSend (fastifyRequest, fastifyReply, payload, next) {
4444
const etag = fastifyReply.getHeader('etag')
4545
if (!etag || !fastifyReply._etagLife) return next()
4646
this.cache.set(
47-
{id: etag, segment: this.cacheSegment},
47+
{ id: etag, segment: this.cacheSegment },
4848
true,
4949
fastifyReply._etagLife,
5050
next
@@ -86,7 +86,7 @@ function fastifyCachingPlugin (instance, options, next) {
8686
}
8787

8888
module.exports = fp(fastifyCachingPlugin, {
89-
fastify: '^1.1.0',
89+
fastify: '^1.0.0',
9090
name: 'fastify-caching'
9191
})
9292

test/cache.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('cache is usable', (t) => {
2323
instance.register(plugin)
2424

2525
instance.get('/one', (req, reply) => {
26-
instance.cache.set('one', {one: true}, 100, (err) => {
26+
instance.cache.set('one', { one: true }, 100, (err) => {
2727
if (err) return reply.send(err)
2828
reply.redirect('/two')
2929
})
@@ -32,7 +32,7 @@ test('cache is usable', (t) => {
3232
instance.get('/two', (req, reply) => {
3333
instance.cache.get('one', (err, obj) => {
3434
if (err) t.threw(err)
35-
t.deepEqual(obj.item, {one: true})
35+
t.deepEqual(obj.item, { one: true })
3636
reply.send()
3737
})
3838
})
@@ -60,7 +60,7 @@ test('etags get stored in cache', (t) => {
6060
instance.get('/one', (req, reply) => {
6161
reply
6262
.etag('123456')
63-
.send({hello: 'world'})
63+
.send({ hello: 'world' })
6464
})
6565

6666
instance.listen(0, (err) => {
@@ -96,7 +96,7 @@ test('etag cache life is customizable', (t) => {
9696
instance.get('/one', function (req, reply) {
9797
reply
9898
.etag('123456', 50)
99-
.send({hello: 'world'})
99+
.send({ hello: 'world' })
100100
})
101101

102102
instance.listen(0, (err) => {

test/headers.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ test('decorators add headers', (t) => {
4747
test('sets no-cache header', (t) => {
4848
t.plan(2)
4949
const instance = fastify()
50-
instance.register(plugin, {privacy: plugin.privacy.NOCACHE})
50+
instance.register(plugin, { privacy: plugin.privacy.NOCACHE })
5151
instance.get('/', (req, reply) => {
52-
reply.send({hello: 'world'})
52+
reply.send({ hello: 'world' })
5353
})
5454
instance.listen(0, (err) => {
5555
if (err) t.threw(err)
@@ -73,7 +73,7 @@ test('sets private with max-age header', (t) => {
7373
}
7474
instance.register(plugin, opts)
7575
instance.get('/', (req, reply) => {
76-
reply.send({hello: 'world'})
76+
reply.send({ hello: 'world' })
7777
})
7878
instance.listen(0, (err) => {
7979
if (err) t.threw(err)
@@ -91,9 +91,9 @@ test('sets private with max-age header', (t) => {
9191
test('sets no-store with max-age header', (t) => {
9292
t.plan(2)
9393
const instance = fastify()
94-
instance.register(plugin, {privacy: 'no-store', expiresIn: 300})
94+
instance.register(plugin, { privacy: 'no-store', expiresIn: 300 })
9595
instance.get('/', (req, reply) => {
96-
reply.send({hello: 'world'})
96+
reply.send({ hello: 'world' })
9797
})
9898
instance.listen(0, (err) => {
9999
if (err) t.threw(err)
@@ -112,11 +112,11 @@ test('sets the expires header', (t) => {
112112
t.plan(2)
113113
const now = new Date()
114114
const instance = fastify()
115-
instance.register(plugin, {privacy: plugin.privacy.NOCACHE})
115+
instance.register(plugin, { privacy: plugin.privacy.NOCACHE })
116116
instance.get('/', (req, reply) => {
117117
reply
118118
.expires(now)
119-
.send({hello: 'world'})
119+
.send({ hello: 'world' })
120120
})
121121
instance.listen(0, (err) => {
122122
if (err) t.threw(err)

0 commit comments

Comments
 (0)