fastify-caching
Advanced tools
Comparing version 3.0.0 to 4.0.0
{ | ||
"name": "fastify-caching", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "A plugin for Fastify to enable management of cache control headers", | ||
"main": "plugin.js", | ||
"scripts": { | ||
"test": "tap 'test/**/*.test.js'", | ||
"test-ci": "tap --cov 'test/**/*.test.js'", | ||
"lint": "standard | snazzy", | ||
"test": "tap test/*.test.js", | ||
"test-ci": "tap --cov test/*.test.js", | ||
"lint": "standard --verbose | snazzy", | ||
"lint-ci": "standard" | ||
@@ -32,13 +32,13 @@ }, | ||
"devDependencies": { | ||
"fastify": "^1.1.0", | ||
"fastify": "2.0.0-rc.0", | ||
"pre-commit": "^1.2.2", | ||
"snazzy": "^7.1.1", | ||
"standard": "^11.0.0", | ||
"tap": "^11.1.1" | ||
"snazzy": "^8.0.0", | ||
"standard": "^12.0.1", | ||
"tap": "^12.1.0" | ||
}, | ||
"dependencies": { | ||
"abstract-cache": "^1.0.1", | ||
"fastify-plugin": "^0.2.2", | ||
"fastify-plugin": "^1.2.1", | ||
"uid-safe": "^2.1.5" | ||
} | ||
} |
@@ -5,6 +5,8 @@ 'use strict' | ||
const uidSafe = require('uid-safe') | ||
const abstractCache = require('abstract-cache') | ||
const defaultOptions = { | ||
expiresIn: undefined, | ||
privacy: undefined, | ||
cache: require('abstract-cache')(), | ||
cache: undefined, | ||
cacheSegment: 'fastify-caching' | ||
@@ -32,7 +34,6 @@ } | ||
const etag = req.headers['if-none-match'] | ||
this.cache.get({id: etag, segment: this.cacheSegment}, (err, cached) => { | ||
this.cache.get({ id: etag, segment: this.cacheSegment }, (err, cached) => { | ||
if (err) return next(err) | ||
if (cached && cached.item) { | ||
res.statusCode = 304 | ||
return res.end() | ||
return res.status(304).send() | ||
} | ||
@@ -47,3 +48,3 @@ next() | ||
this.cache.set( | ||
{id: etag, segment: this.cacheSegment}, | ||
{ id: etag, segment: this.cacheSegment }, | ||
true, | ||
@@ -63,3 +64,3 @@ fastifyReply._etagLife, | ||
if (!_options.cache) _options.cache = defaultOptions.cache | ||
if (!_options.cache) _options.cache = abstractCache() | ||
@@ -91,3 +92,3 @@ if (_options.privacy) { | ||
module.exports = fp(fastifyCachingPlugin, { | ||
fastify: '^1.1.0', | ||
fastify: '^2.0.0', | ||
name: 'fastify-caching' | ||
@@ -94,0 +95,0 @@ }) |
# fastify-caching | ||
[![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) | ||
*fastify-caching* is a plugin for the [Fastify](http://fastify.io/) framework | ||
that provides mechanisms for manipulating HTTP cache headers according to | ||
[RFC 2616 §14.9](https://tools.ietf.org/html/rfc2616#section-14.9). | ||
[RFC 2616 §14.9](https://tools.ietf.org/html/rfc2616#section-14.9). | ||
Supports Fastify versions ^2.0.0. | ||
This plugin fully supports Fastify's encapsulation. Therefore, routes that | ||
@@ -8,0 +12,0 @@ should have differing cache settings should be registered within different |
@@ -26,3 +26,3 @@ 'use strict' | ||
instance.get('/one', (req, reply) => { | ||
instance.cache.set('one', {one: true}, 100, (err) => { | ||
instance.cache.set('one', { one: true }, 100, (err) => { | ||
if (err) return reply.send(err) | ||
@@ -36,3 +36,3 @@ reply.redirect('/two') | ||
if (err) t.threw(err) | ||
t.deepEqual(obj.item, {one: true}) | ||
t.deepEqual(obj.item, { one: true }) | ||
reply.send() | ||
@@ -65,3 +65,3 @@ }) | ||
.etag('123456') | ||
.send({hello: 'world'}) | ||
.send({ hello: 'world' }) | ||
}) | ||
@@ -102,3 +102,3 @@ | ||
.etag('123456', 50) | ||
.send({hello: 'world'}) | ||
.send({ hello: 'world' }) | ||
}) | ||
@@ -105,0 +105,0 @@ |
@@ -50,5 +50,5 @@ 'use strict' | ||
const instance = fastify() | ||
instance.register(plugin, {privacy: plugin.privacy.NOCACHE}) | ||
instance.register(plugin, { privacy: plugin.privacy.NOCACHE }) | ||
instance.get('/', (req, reply) => { | ||
reply.send({hello: 'world'}) | ||
reply.send({ hello: 'world' }) | ||
}) | ||
@@ -77,3 +77,3 @@ instance.listen(0, (err) => { | ||
instance.get('/', (req, reply) => { | ||
reply.send({hello: 'world'}) | ||
reply.send({ hello: 'world' }) | ||
}) | ||
@@ -96,5 +96,5 @@ instance.listen(0, (err) => { | ||
const instance = fastify() | ||
instance.register(plugin, {privacy: 'no-store', expiresIn: 300}) | ||
instance.register(plugin, { privacy: 'no-store', expiresIn: 300 }) | ||
instance.get('/', (req, reply) => { | ||
reply.send({hello: 'world'}) | ||
reply.send({ hello: 'world' }) | ||
}) | ||
@@ -118,7 +118,7 @@ instance.listen(0, (err) => { | ||
const instance = fastify() | ||
instance.register(plugin, {privacy: plugin.privacy.NOCACHE}) | ||
instance.register(plugin, { privacy: plugin.privacy.NOCACHE }) | ||
instance.get('/', (req, reply) => { | ||
reply | ||
.expires(now) | ||
.send({hello: 'world'}) | ||
.send({ hello: 'world' }) | ||
}) | ||
@@ -125,0 +125,0 @@ instance.listen(0, (err) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17287
8
148
3
+ Addedfastify-plugin@1.6.1(transitive)
+ Addedsemver@6.3.1(transitive)
- Removedfastify-plugin@0.2.2(transitive)
- Removedsemver@5.7.2(transitive)
Updatedfastify-plugin@^1.2.1