Skip to content

TallerWebSolutions/express-cache-tags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

Any request will be cached using the request URL as basic cache-tag for invalidation. If a Cache-Tags header is present on any response, it will be considered as well.

MISSes and HITs will be logged by default.

Invalidation

You can purge specific tags by sending GET requests to /_cache/purge?invalidate=[TAG NAME]. You can also purge by URL, by sending the URL as invalidate query param.

Options

All the usage options receive the same options object:

prop description default
cacheFactory A cache-object factory A new memory-cache instace
generateKey A cache-key generator (req) => \${req.method}:${rq.url}``
shouldCache Predicate to decide caching () => true // cache anything the middleware touches
statusHeader Hitting status header name 'CDN-Cache'
logger Logging specific options
logger.enabled Wheter or not to log operations true
logger.scope Logging scope (see signale) 'CACHE'
cacheTags Cache-tags specific options
cacheTags.extract Request cache-tags extractor `(req, res) => (res.get('Cache-Tags')
purger Purging specific options
purger.extract Purging tags extractor `(req, res) => (req.query.invalidate
Cache-object

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

About

A (not yet) fully featured caching solution for node servers.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published