Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
},
"homepage": "https://github.com/fastify/fastify-caching#readme",
"devDependencies": {
"fastify": "^0.35.2",
"fastify": "^0.39.1",
"pre-commit": "^1.2.2",
"snazzy": "^7.0.0",
"standard": "^10.0.3",
"tap": "^10.7.3"
"tap": "^11.0.1"
},
"dependencies": {
"abstract-cache": "^1.0.0",
"fastify-plugin": "^0.1.1",
"fastify-plugin": "^0.2.1",
"uid-safe": "^2.1.5"
}
}
5 changes: 4 additions & 1 deletion plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function fastifyCachingPlugin (instance, options, next) {
next()
}

module.exports = fp(fastifyCachingPlugin, '>=0.33.0')
module.exports = fp(fastifyCachingPlugin, {
fastify: '>=0.39.1',
name: 'fastify-caching'
})

module.exports.privacy = {
NOCACHE: 'no-cache',
Expand Down
24 changes: 9 additions & 15 deletions test/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ const fastify = require('fastify')
test('cache property gets added to instance', (t) => {
t.plan(2)
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)

t.ok(instance.cache)
t.ok(instance.cache.set)
})
instance
.register(plugin)
.ready(() => {
t.ok(instance.cache)
t.ok(instance.cache.set)
})
})

test('cache is usable', (t) => {
t.plan(1)
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)
})
instance.register(plugin)

instance.get('/one', (req, reply) => {
instance.cache.set('one', {one: true}, 100, (err) => {
Expand Down Expand Up @@ -57,9 +55,7 @@ test('cache is usable', (t) => {
test('etags get stored in cache', (t) => {
t.plan(1)
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)
})
instance.register(plugin)

instance.get('/one', (req, reply) => {
reply
Expand Down Expand Up @@ -95,9 +91,7 @@ test('etags get stored in cache', (t) => {
test('etag cache life is customizable', (t) => {
t.plan(1)
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)
})
instance.register(plugin)

instance.get('/one', function (req, reply) {
reply
Expand Down
24 changes: 6 additions & 18 deletions test/headers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ const fastify = require('fastify')
test('decorators get added', (t) => {
t.plan(1)
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)
})
instance.register(plugin)
instance.get('/', (req, reply) => {
t.ok(reply.etag)
reply.send()
Expand All @@ -28,9 +26,7 @@ test('decorators add headers', (t) => {
t.plan(2)
const tag = '123456'
const instance = fastify()
instance.register(plugin, (err) => {
if (err) t.threw(err)
})
instance.register(plugin)
instance.get('/', (req, reply) => {
reply
.etag(tag)
Expand All @@ -51,9 +47,7 @@ test('decorators add headers', (t) => {
test('sets no-cache header', (t) => {
t.plan(2)
const instance = fastify()
instance.register(plugin, {privacy: plugin.privacy.NOCACHE}, (err) => {
if (err) t.threw(err)
})
instance.register(plugin, {privacy: plugin.privacy.NOCACHE})
instance.get('/', (req, reply) => {
reply.send({hello: 'world'})
})
Expand All @@ -77,9 +71,7 @@ test('sets private with max-age header', (t) => {
privacy: plugin.privacy.PRIVATE,
expiresIn: 300
}
instance.register(plugin, opts, (err) => {
if (err) t.threw(err)
})
instance.register(plugin, opts)
instance.get('/', (req, reply) => {
reply.send({hello: 'world'})
})
Expand All @@ -99,9 +91,7 @@ test('sets private with max-age header', (t) => {
test('sets no-store with max-age header', (t) => {
t.plan(2)
const instance = fastify()
instance.register(plugin, {privacy: 'no-store', expiresIn: 300}, (err) => {
if (err) t.threw(err)
})
instance.register(plugin, {privacy: 'no-store', expiresIn: 300})
instance.get('/', (req, reply) => {
reply.send({hello: 'world'})
})
Expand All @@ -122,9 +112,7 @@ test('sets the expires header', (t) => {
t.plan(2)
const now = new Date()
const instance = fastify()
instance.register(plugin, {privacy: plugin.privacy.NOCACHE}, (err) => {
if (err) t.threw(err)
})
instance.register(plugin, {privacy: plugin.privacy.NOCACHE})
instance.get('/', (req, reply) => {
reply
.expires(now)
Expand Down