Download Latest Version Add .take() and .flushStats() source code.tar.gz (85.7 kB)
Email in envelope

Get an email when there's a new version of node-cache

Home / v5.0.0
Name Modified Size InfoDownloads / Week
Parent folder
Drop lodash dependency and callbacks source code.tar.gz 2019-10-23 84.6 kB
Drop lodash dependency and callbacks source code.zip 2019-10-23 89.3 kB
README.md 2019-10-23 1.5 kB
Totals: 3 Items   175.4 kB 0
  • Remove lodash dependency
  • DROP CALLBACK SUPPORT - Read the migration guide if you are currently using the callback based api! :warning:
  • add .has(key) and method - Thanks to Regev Brody for PR [#132]!
  • add .mset([{key,val,ttl}]) method - Thanks to Sujesh Thekkepatt for PR [#142]!
  • add maxKeys setting to limit cache size - Thanks do @daluf for PR [#141]!
  • Also, thank you to all other contributors that remain unnamed here! :tada:

MIGRATION GUIDE :construction:

We have dropped callback support in node-cache and you should migrate to our sync-style api!

If you cannot refactor right now, you can turn on legacy callback support by enabling the enableLegacyCallbacks option. Eg: const cache = new NodeCache({ enableLegacyCallbacks: true })

But we strongly recommend to refactor your code to use the sync-api because we will drop official callback support in Versions v6.x and onwards.

If your code currently looks like this:

:::javascript
cache.get("my-key", function(err, value) {
  if (err) {
     // ...
  }

  // double equal checks for null and undefined
  if (value != null) {
    // hmm.... nothing here :(
  }

  // do something with value
});

it should be rewritten to:

:::javascript
const value = cache.get("my-key");

// double equal checks for null and undefined
if (value != null) {
  // hmm.... nothing here :(
}

// do something with value
Source: README.md, updated 2019-10-23