Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

upcache

kapouer172MIT2.8.2

nginx proxy cache key protocols implementations

cache, protocols, nginx, proxy, purge, lua, upstream

readme

upcache

Caching proxy having cache keys configured by the upstream application, by setting http response headers.

Upcache has several ways of changing the cache keys:

  • tag, version resources by zones
  • lock, vary on client json web token grants
  • vary, vary by grouping selected request headers
  • map, maps a request uri to another request uri

Breaking change: server.d/upcache.conf is now server.d/upcache-memcached.conf

Requirements

In debian/12 these packages are easy to install:

  • nginx
  • libnginx-mod-http-srcache-filter
  • libnginx-mod-http-set-misc
  • libnginx-mod-http-memc (if using memcached, or for running the test suite
  • memcached or redis
  • lua-resty-core
  • lua-resty-lrucache

  • a Node.js express app

Install

The Node.js app need the module

npm install upcache

The nginx configuration need the module

luarocks install upcache

nginx is easily configured with the set of files described in (depending on where npm installs the module) ./node_modules/upcache/nginx/README.md.

Usage

Once installed, load appropriate helpers with

const app = express();
const { tag, lock } = require('upcache');
const mlock = lock(config);

app.get('/route', tag('ugc', 'global'), mlock.restrict('logged'), ...);
app.post('/route', tag(), mlock.restrict('logged'), ...);

See README-tag.md and README-lock.md for documentation, and test/ for more examples.

Mind that srcache module honours cache control headers - if the application sends responses with Cache-Control: max-age=0, the resource is not cached, and tag().for() is a facility for doing cache control.

To cache something, resources must be tagged, so lock/vary won't work without tag.

Detection by upstream

Upcache adds a X-Upcache: <version> header to requests, so upstream application can detect it is enabled, and which features are available.

Testing

A pre-configured nginx environment is available for testing a Node.js application that listens on port 3000, with nginx on port 3001 and memcached on port 3002, simply by launching (depending on ./node_modules/.bin being on PATH or not)

npm run upcache

which also has an option for filtering output -g <regexp pattern>.

mocha relies on it for integration tests. No root permissions are needed.

License

See LICENSE file.

changelog

CHANGES

0.5.0

  • introduced scope.sign(user, opts) to get a jwt without reference to express
  • refactor how variants are stored - use the same shared dictionnary
  • update nginx config to allow more memory for the shared dictionnaries
  • pass HttpError from http-errors module for throwing forbidden/unauthorized errors. The corresponding scope() options are no longer in use.

0.6.0

  • factored restrict and allowed, renamed allowed to test
  • parametrized scopes now correctly return wildcard headers

0.7.0

  • issuer is the hostname and cannot be configured

0.8.0

  • scope.serializeBearer(req, user, opts)
  • make luarocks installs lua modules in a local tree

0.9.0

  • nothing is cached unless tagged
  • no particular peremption is set (used to be 1 day by default if nothing was set)

1.0.0

  • major breaking changes: scopes are now locks and has been simplified a lot.

2.2.0

  • upcache.disabled (the lua module) let lua-ngx code disable upcache

2.6.0

  • more es6 javascript
  • fix Vary handling when no response header is set
  • test Vary with Map

2.7.0

  • tag.for cannot override tag.disable
  • better support for headers lists

2.8.0

  • lock: req.user.grants is always set