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
nginx >= 1.8, with these openresty's modules
lua-nginx-module (with luajit enabled or else it fails with missing ffi package)
memc-nginx-module (if using memcached)
memcached or redis
a Node.js express app
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)
Once installed, load appropriate helpers with
var app = express(); var tag = require('upcache').tag; var lock = require('upcache').lock(config); app.get('/route', tag('ugc', 'global'), lock.restrict('logged'), ...); app.post('/route', tag(), lock.restrict('logged'), ...);
See README-tag.md and README-lock.md for documentation, and test/ for more examples.
srcache module honours cache control headers - if the application
sends responses with
Cache-Control: max-age=0, the resource is not cached,
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.
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.
See LICENSE file.