Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getOrElse missing in the latest version #52

Open
advapiIT opened this issue Nov 24, 2020 · 1 comment
Open

getOrElse missing in the latest version #52

advapiIT opened this issue Nov 24, 2020 · 1 comment

Comments

@advapiIT
Copy link

Hello,
It's the first time I use node-cache (I normally develop in c#), I've seen that's available on the doc the getOrElse method, I've tried with the following code but I got a getOrElse is not a myCache function error..

Here's the snippet of my class

const NodeCache = require( "node-cache" );
const myCache = new NodeCache();

var quadCache = {};

quadCache.setKey= function(key,obj, ttl)
{
    success = myCache.set( key, obj, ttl | 10000 );
    return success;
}

quadCache.getKey= function(key)
{
    value = myCache.get( key )

    if(value == undefined)
    {
        return null;
    }

    return value;

}

quadCache.getOrAdd = async function(key,funzione,ttl=20000)
{
    return myCache.getOrElse( key, await funzione(), ttl | 10000 );
}

module.exports = quadCache;

What am I doing wrong?
Thanks

@Juraj-Masiar
Copy link

You have a wrong import, it should be require('cached').
There is no constructor, so no such thing as new NodeCache();.
Is that a bitwise OR??? ttl | 10000 :D, I think you meant to use ttl || 10000.
Check the example code in the readme for simple usage of this library.

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

No branches or pull requests

2 participants