[{"title":"API Reference","content":"SET\n\nmyCache.set(key, val, [ttl])\n\nSets a key-value pair. Optional ttl in seconds. Returns true on success.\n\nobj = { my: \"Special\", variable: 42 };\nsuccess = myCache.set(\"myKey\", obj, 10000);\n// true\n\nMSET\n\nmyCache.mset(Array<{key, val, ttl?}>)\n\nSets multiple key-value pairs. Returns true on success.\n\nconst success = myCache.mset([\n  { key: \"myKey\", val: obj, ttl: 10000 },\n  { key: \"myKey2\", val: obj2 },\n]);\n\nGET\n\nmyCache.get(key)\n\nGets a saved value. Returns undefined if not found or expired.\n\nvalue = myCache.get(\"myKey\");\nif (value === undefined) {\n  // handle miss!\n}\n// { my: \"Special\", variable: 42 }\n\nTAKE\n\nmyCache.take(key)\n\nGets the cached value and removes the key from the cache. Equivalent to get(key) + del(key).\n\nmyCache.set(\"myKey\", \"myValue\");\nvalue = myCache.take(\"myKey\");\n// value === \"myValue\"; key is deleted\nmyCache.has(\"myKey\"); // false\n\nMGET\n\nmyCache.mget([ key1, key2, ..., keyn ])\n\nGets multiple values. Returns an object of key-value pairs.\n\nvalue = myCache.mget([\"myKeyA\", \"myKeyB\"]);\n/*\n  {\n    \"myKeyA\": { my: \"Special\", variable: 123 },\n    \"myKeyB\": { the: \"Glory\", answer: 42 }\n  }\n*/\n\nDEL\n\nmyCache.del(key) or myCache.del([ key1, key2, ... ])\n\nDeletes one or multiple keys. Returns the number of deleted entries.\n\nmyCache.del(\"A\");\n// 1\n\nmyCache.del([\"B\", \"C\"]);\n// 2\n\nTTL\n\nmyCache.ttl(key, ttl)\n\nRedefines the TTL of a key. Returns true if found and changed.\n\nmyCache = new NodeCache({ stdTTL: 100 });\nchanged = myCache.ttl(\"existentKey\", 100);\n// true\n\nchanged2 = myCache.ttl(\"missingKey\", 100);\n// false\n\ngetTTL\n\nmyCache.getTtl(key)\n\nReturns:\n\nundefined if the key does not exist\n\n0 if the key has no TTL\n\na timestamp in ms representing the expiry time\n\nts = myCache.getTtl(\"ttlKey\");\n// approximately 1456000600000\n\nts = myCache.getTtl(\"noTtlKey\");\n// 0\n\nts = myCache.getTtl(\"unknownKey\");\n// undefined\n\nKEYS\n\nmyCache.keys()\n\nReturns an array of all existing keys.\n\nmykeys = myCache.keys();\n// [ \"all\", \"my\", \"keys\", \"foo\", \"bar\" ]\n\nHAS\n\nmyCache.has(key)\n\nReturns boolean indicating if the key is cached.\n\nexists = myCache.has(\"myKey\");\nconsole.log(exists);\n\ngetStats\n\nmyCache.getStats()\n\nReturns cache statistics.\n\nmyCache.getStats();\n/*\n  {\n    keys: 0,    // global key count\n    hits: 0,    // global hit count\n    misses: 0,  // global miss count\n    ksize: 0,   // global key size in bytes\n    vsize: 0    // global value size in bytes\n  }\n*/\n\nflushAll\n\nmyCache.flushAll()\n\nFlushes all cached data.\n\nmyCache.flushAll();\nmyCache.getStats();\n// { keys: 0, hits: 0, misses: 0, ksize: 0, vsize: 0 }\n\nflushStats\n\nmyCache.flushStats()\n\nFlushes only the statistics.\n\nmyCache.flushStats();\n\nclose\n\nmyCache.close()\n\nClears the interval timeout set by the check period option.\n\nmyCache.close();","routePath":"/guide/api","lang":"en","toc":[{"id":"set","text":"SET","depth":2,"charIndex":0},{"id":"mset","text":"MSET","depth":2,"charIndex":201},{"id":"get","text":"GET","depth":2,"charIndex":413},{"id":"take","text":"TAKE","depth":2,"charIndex":613},{"id":"mget","text":"MGET","depth":2,"charIndex":867},{"id":"del","text":"DEL","depth":2,"charIndex":1125},{"id":"ttl","text":"TTL","depth":2,"charIndex":1309},{"id":"getttl","text":"getTTL","depth":2,"charIndex":1548},{"id":"keys","text":"KEYS","depth":2,"charIndex":1848},{"id":"has","text":"HAS","depth":2,"charIndex":1977},{"id":"getstats","text":"getStats","depth":2,"charIndex":2103},{"id":"flushall","text":"flushAll","depth":2,"charIndex":2394},{"id":"flushstats","text":"flushStats","depth":2,"charIndex":2546},{"id":"close","text":"close","depth":2,"charIndex":2633}],"frontmatter":{},"version":""},{"title":"Events","content":"set\n\nFired when a key has been added or changed.\n\nmyCache.on(\"set\", function(key, value) {\n  // ... do something ...\n});\n\ndel\n\nFired when a key has been removed manually or due to expiry.\n\nmyCache.on(\"del\", function(key, value) {\n  // ... do something ...\n});\n\nexpired\n\nFired when a key expires.\n\nmyCache.on(\"expired\", function(key, value) {\n  // ... do something ...\n});\n\nflush\n\nFired when the cache has been flushed.\n\nmyCache.on(\"flush\", function() {\n  // ... do something ...\n});\n\nflush_stats\n\nFired when the cache stats have been flushed.\n\nmyCache.on(\"flush_stats\", function() {\n  // ... do something ...\n});","routePath":"/guide/events","lang":"en","toc":[{"id":"set","text":"set","depth":2,"charIndex":0},{"id":"del","text":"del","depth":2,"charIndex":122},{"id":"expired","text":"expired","depth":2,"charIndex":261},{"id":"flush","text":"flush","depth":2,"charIndex":373},{"id":"flush_stats","text":"flush_stats","depth":2,"charIndex":484}],"frontmatter":{},"version":""},{"title":"Getting Started","content":"Install\n\nnpm install node-internal-cache --save\n\nInitialize\n\nconst NodeCache = require(\"node-internal-cache\");\nconst myCache = new NodeCache();\n\nOptions\n\nOption\tType\tDefault\tDescription\nstdTTL\tnumber\t0\tStandard ttl in seconds for every generated cache element. 0 = unlimited\ncheckperiod\tnumber\t600\tPeriod in seconds for the automatic delete check interval. 0 = no periodic check\nuseClones\tboolean\ttrue\tEn/disable cloning of variables. true returns a copy. false saves and returns just the reference\ndeleteOnExpire\tboolean\ttrue\tWhether variables will be deleted automatically when they expire\nenableLegacyCallbacks\tboolean\tfalse\tRe-enables usage of callbacks instead of sync functions\nmaxKeys\tnumber\t-1\tMaximum amount of keys. -1 disables the limit\n\nconst NodeCache = require(\"node-internal-cache\");\nconst myCache = new NodeCache({ stdTTL: 100, checkperiod: 120 });\n\nSince 4.1.0: keys can be given as string or number, but are cast to string internally. All other types throw an error.","routePath":"/guide/getting-started","lang":"en","toc":[{"id":"install","text":"Install","depth":2,"charIndex":0},{"id":"initialize","text":"Initialize","depth":2,"charIndex":49},{"id":"options","text":"Options","depth":3,"charIndex":145}],"frontmatter":{},"version":""}]