0

I used cluster-node-cache with following code.

var obj = { my: "Special", variable: 42 };
        cache.set("myKey", obj).then(function(result) {
                console.log(result.err);
                console.log(result.success);

                cache.get("myKey").then(function(result2) {
                    console.log(result2.err);
                    console.log(result2.success);
                });

        });

This resulted in following output

null
true
null
undefined

Certainly, with this result, cluster-node-cache is not a solution for caching requirement with cluster.
Please suggest best solution and why that solution is best?

Lokinder Singh Chauhan
  • 2,326
  • 1
  • 20
  • 23
  • The code as written doesn't even make sense; you're asking for `result2.success` which *is* `undefined`. According to the node-cache docs, the result of a `get` is an object with `err` and `value` keys. If nothing else, I'd at least recommend following the actual API before deciding whether or not it works for you. – Dave Newton Dec 10 '16 at 19:01
  • Hi @DaveNewton I have followed example code form cluster-node-cache github page. I know there should be err object in callback but example in github page of library says other way. – Lokinder Singh Chauhan Dec 12 '16 at 06:36
  • Look at the docs for get: https://github.com/lvx3/cluster-cache/blob/master/README.md – Dave Newton Dec 12 '16 at 10:48
  • Hi @DaveNewton please have look over this example .. myCache.get(["keyA", "keyB"]).then(function(results) { if(results.err) { console.log(results.err); } else { console.log(results.value); } }); ... – Lokinder Singh Chauhan Dec 12 '16 at 11:47
  • Hi @DaveNewton please have look over this example code from link given by you( on Retrieve a key (GET): heading) ...... eyCache.get("myKey").then(function(results) { if(results.err) { console.log(results.err); } else { console.log(results.value.myKey); } }); ... there is no err object here!! .. I am great full for your time. – Lokinder Singh Chauhan Dec 12 '16 at 11:52
  • Correct, because you're not getting an error. – Dave Newton Dec 12 '16 at 11:55

1 Answers1

1

Since memory data is not shared among different processes, cluster cache does not seems to solve problem of caching in clustered nodejs application.

I solved this caching issue with redis server. redis server have good performance and it can be clustered further(for bigger applications)

Lokinder Singh Chauhan
  • 2,326
  • 1
  • 20
  • 23