Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

using catbox-fallback with Glue manifest? #1

Open
emckean opened this issue Feb 26, 2019 · 4 comments
Open

using catbox-fallback with Glue manifest? #1

emckean opened this issue Feb 26, 2019 · 4 comments
Assignees

Comments

@emckean
Copy link

emckean commented Feb 26, 2019

I'm unclear on how to use catbox-fallback in my hapi project Glue manifest for server.cache -- any pointers to examples available?

I promise to do a pull request for the docs if I get enough examples to understand it. :)

@simlevesque
Copy link
Contributor

simlevesque commented Feb 26, 2019

if you can show me your code I could try to run it and help you. I think you can use catbox-fallback like any other plugin.

edit: I added an example, hope it helps: https://github.com/Tractr/catbox-fallback/blob/master/examples/simple.js

@simlevesque simlevesque self-assigned this Feb 26, 2019
@emckean
Copy link
Author

emckean commented Feb 26, 2019

yes, thank you! That helps a lot! I was also wondering how to reference it in server methods (as in this gist: https://gist.github.com/emckean/3565c1c0d43a20c07df7b101d1bcc995) -- can the client be referenced by name?

@emckean
Copy link
Author

emckean commented Mar 24, 2019

hi! I'm still working on this, I'm trying this inside the Glue manifest:

const Glue = require('glue');
const manifest = {
    server: {
        cache: [ 
            // {
            //     name: 'redisCache',
            //     engine: require('catbox-redis'),
            //     url: redisConfig.url,
            //     password: redisConfig.password,
            //     partition: redisConfig.partition
            // }
            new Catbox.Client(CatboxFallback, {
                primary: {
                    engine: new CatboxRedis({
                        partition: redisConfig.partition,
                        url: redisConfig.url,
                        password: redisConfig.password
                    })
                },
                secondary: {
                    engine: new CatboxMemory()
                }
            })
        ],

(commented out is previously working code)
But I get this error: AssertionError [ERR_ASSERTION]: Must set a primary engine

Enclosing the new Catbox.Client in {} gets SyntaxError: Unexpected identifier (on Catbox)
Setting up a separate const client = also gets the "Must set a primary engine" error.

Any suggestions gratefully received!

@EdouardDem
Copy link
Member

This post is a bit old but this may help someone.
I fixed the example: https://github.com/Tractr/catbox-fallback/blob/master/examples/simple.js

Using Hapi17, the configuration is working like this:

const server = Hapi.server({
    port: 3000,
    host: 'localhost',
    cache: {
        name: 'fallback',
        engine: CatboxFallback,
        primary: {
            engine: CatboxRedis,
            options: {
                partition: 'example',
                host: '127.0.0.1',
                port: 6379,
            }
        },
        secondary: {
            engine: CatboxMemory,
        }
    }
});

Using Hapi18, this works:

const server = Hapi.server({
    port: 3000,
    host: 'localhost',
    cache: {
        name: 'fallback',
        provider: {
            constructor: CatboxFallback,
            options: {
                primary: {
                    engine: CatboxRedis,
                    options: {
                        partition: 'example',
                        host: '127.0.0.1',
                        port: 6379,
                    }
                },
                secondary: {
                    engine: CatboxMemory,
                }
            }
        }
    }
});

Hope this helps

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants