Hapi Cache Manager
Hapi Cache Manager plugin
Manage your Catbox cache through REST endpoints and server methods.
Plugin options
namespace
- (Default: cache
) Namespace for methods registered by the plugin.invalidate
- Cache invalidation options object
path
- (Default: /cache/invalidate
) Server endpoint to expose through DELETE methodauth
- (Default: false
) Hapi auth strategy to use for cache invalidation endpoint
statistics
- Cache statistics options object
path
- (Default: /cache/statistics
) Server endpoint to expose through GET methodauth
- (Default: false
) Hapi auth strategy to use for cache statistics endpoint
Installation
const Hapi = require('hapi');
const CacheManager = require('hapi-cache-manager');
const server = new Hapi.Server();
server.connection({ port: 3000 });
server.register({
register: CacheManager,
options: {
namespace: 'cache',
invalidate: {
path: 'cache/invalidate',
auth: false
},
statistics: {
path: 'cache/statistics',
auth: false
}
}
}, (err) => {
if (err) {
throw err;
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log('Server started');
});
Cache Statistics
You can get cache statistics for a single method or for all methods registered on the server:
curl http://localhost:3000/cache/statistics
curl http://localhost:3000/cache/statistics\?name\=somemethod
Cache Invalidation
You can drop as many cached keys for as many methods as you want with either a single external request or internally by calling a server method.
const payload = {
data: [
{ name: 'methodname', keys: ['blabla', '123'] },
{ name: 'someothermethodname', keys: ['abc'] },
{ ... }
]
};
server.inject({ method: 'DELETE', url: '/cache/invalidate', payload: payload }, (res) => {
console.log(res.statusCode)
console.log(res.payload == '');
});
server.methods.cache.invalidate(payload, (err, res) => {
});
MIT Public License.