# Catbox cache calls fail in 6.5+

**URL:** <https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019>\
**Category:** Kibana\
**Created:** [January 5, 2019, 12:34am UTC](https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019 "2019-01-05T00:34:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![znwilkins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/znwilkins/32/39486_2.png) [@znwilkins](https://discuss.elastic.co/u/znwilkins)\
**Post date:** [January 5, 2019, 12:34am UTC](https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019/1 "2019-01-05T00:34:54Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![azasypkin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/azasypkin/32/42216_2.png) [@azasypkin](https://discuss.elastic.co/u/azasypkin)\
**Post date:** [January 7, 2019, 12:10pm UTC](https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019/2 "2019-01-07T12:10:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![znwilkins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/znwilkins/32/39486_2.png) [@znwilkins](https://discuss.elastic.co/u/znwilkins)\
**Post date:** [January 7, 2019, 4:11pm UTC](https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019/3 "2019-01-07T16:11:26Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 4, 2019, 4:11pm UTC](https://discuss.elastic.co/t/catbox-cache-calls-fail-in-6-5/163019/4 "2019-02-04T16:11:34Z")

</div>

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