Cache insights for Hapi.js servers with Catbox cache policies
npm i @jameswragg/hapi-cache-statsRegister the plugin as (one of) the first plugins on the server to ensure policies are caught.
const Hapi = require('@hapi/hapi');
const HapiCacheStats = require('@jameswragg/hapi-cache-stats');
(async () => {
const server = Hapi.server({ port: 3000 });
await server.register({
plugin: HapiCacheStats,
options: {
// options here
},
});
// app code here - using Catbox caches
await server.start();
console.log(`Start adding at ${server.info.uri}`);
})();Then visit http://localhost:3000/cache-stats for live, real-time stats on all registered cache policies & method stats.
Seeing what methods use the cache policy & their individual stats

base- route to mount the UI on, default:'/cache-stats'snapshot- object with the following settings regarding snapshots:interval- every X seconds, default:5retention: how many snapshots to retain, default:60
socketIo- socket.io server options, default:{ cors: { origin: '*' } }
To contribute to the project:
- Clone the repo
npm installnpm run dev- will file up an example server with policies, caches and a Vite server to host the frontend
Then append ?dev to the url e.g. http://localhost:3000/cache-stats?dev. This will load the Vue front-end via the Vite server instead of built assets, supporting HMR on change etc.
