Catbox cache calls fail in 6.5+

Hello,

I wrote a Kibana plugin last summer that employs Catbox caching from Hapi, and it's been working quite well until the release of Kibana 6.5.

A simple example:

module.exports = function (server, options) {
const cache = server.cache({ segment: 'segment1', expiresIn: 7200000 });

cache.set('key', 'value', 0, (err) => {});
cache.get('key', (err, value) => {
    if (err) {
        server.log(['error'], 'Error is: ' + err);
    }
    else {
        server.log(['info'], 'Value is: ' + value);
    }
});

};

This produces the following error message:
log [00:18:41.318] [error] Error is: Error: Disconnected

In 6.5 and later, it seems that the memory engine underlying the Catbox policy object is never started, so any get/set calls fail. I've managed to get around this problem by manually starting the engine like so:

if (!cache.isReady()) {
cache._cache.connection.start(() => {
server.log(['info'], 'Started memory cache');
});
}

Which outputs the desired log messages:

log [00:22:01.729] [info] Started memory cache
log [00:22:01.736] [info] Value is: value

Obviously this isn't the preferred approach, however, as it accesses private members of the cache object.

I was going to open an issue on GitHub, but wasn't sure if this qualifies as a bug, or if there's something that I'm missing. Thoughts?

Thanks in advance!

Hi @znwilkins,

Yeah, you're right we don't call start on the server anymore that is likely the reason for the behavior you're observing. We're gradually moving away from exposing raw Hapi server to the plugins and hence all the APIs that we (Kibana) don't specifically provide or advertise are subject to change at any time so we don't recommend relying on these.

Like in this particular case cache will be visible to any other plugins that can access it and accidentally or not override/remove values your plugin put into it, that's not safe.

We admit that this is not ideal and working hard on strictly defining new plugins API and properly documenting it.

For the time being is there any reason why you can't use Catchbox's Client and Policy directly in your plugin without relying on the cache provided by server?

Best,
Oleg

Hi @azasypkin,

Gotcha, thanks for explaining your rationale... makes sense! No, I can definitely work directly with Catbox going forward.

Thanks for getting back to me!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.