1.0.0 • Published 5 years ago

express-cache-tags v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

express-cache-tags

npm version Downloads/week License build status coverage

A (not yet) fully featured cache-tagging solution for node servers.


Motivation

Most HTTP servers rely on third-party systems for caching (such as CDNs). Even though this is probably the right approach, sometimes we need a fully featured, local, and simple caching and puring solution for a varying number of reasons. Whatever the reason is for you, we got you covered!

Usage

Installation

npm i express-cache-tags

Usage

Middleware

import express from 'express'
import cache from 'express-cache-tags'

express()
  .use(cache())
  // .get(...) your server routes
  .listen(3000)

Options

All the usage options receive the same options object:

propdescriptiondefault
cacheFactoryA cache-object factoryA new memory-cache instace
generateKeyA cache-key generator(req) => \${req.method}:${rq.url}``
shouldCachePredicate to decide caching() => true // cache anything the middleware touches
statusHeaderHitting status header name'CDN-Cache'
loggerLogging specific options
logger.enabledWheter or not to log operationstrue
logger.scopeLogging scope (see signale)'CACHE'
cacheTagsCache-tags specific options
cacheTags.extractRequest cache-tags extractor(req, res) => (res.get('Cache-Tags') || '').split(',').filter(Boolean)
purgerPurging specific options
purger.extractPurging tags extractor(req, res) => (req.query.invalidate || '').split(',').filter(Boolean)
Cache-object

A memory-cache compatible object, with at least get, put, keys, and clear methods.