Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-cache-manager

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-cache-manager

Manage your Hapi catbox cache through REST endpoints and server methods.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by75%
Maintainers
1
Weekly downloads
 
Created
Source

Hapi Cache Manager

NPM version Build Status Dependency Status DevDependency Status Coverage Status

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 method
    • auth - (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 method
    • auth - (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: {                        // default options 
        namespace: 'cache',           // server methods namespace
        invalidate: {
          path: 'cache/invalidate',   // cache invalidation endpoint
          auth: false                 // cache invalidation auth strategy
        },
        statistics: {
          path: 'cache/statistics',   // cache invalidation endpoint
          auth: false                 // cache invalidation auth strategy
        }
    }
}, (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:


# get statistics for all methods
curl http://localhost:3000/cache/statistics
# { 
#   'somemethod': { 
#     sets: 0, gets: 2, hits: 1, stales: 0, generates: 1, errors: 0 
#   }, 
#   'someothermethod': { ... } }

# get statistics for a single method
curl http://localhost:3000/cache/statistics\?name\=somemethod
# { 
#   sets: 0, gets: 3, hits: 2, stales: 0, generates: 1, errors: 0 
# }

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'] },
        { ... }
    ]
};

// through REST
server.inject({ method: 'DELETE', url: '/cache/invalidate', payload: payload }, (res) => {
    console.log(res.statusCode)
    // 204
    console.log(res.payload == '');
    // true
});

// through server method
server.methods.cache.invalidate(payload, (err, res) => {
});

MIT Public License.

Keywords

FAQs

Package last updated on 26 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc