node-cache
Advanced tools
Comparing version 5.0.0-alpha.0 to 5.0.0-alpha.1
@@ -15,3 +15,3 @@ import NodeCache = require("../../"); | ||
let options: Options; | ||
let cache: NodeCache.NodeCache; | ||
let cache: NodeCache; | ||
cache = new NodeCache(); | ||
@@ -18,0 +18,0 @@ cache = new NodeCache(options); |
137
index.d.ts
@@ -1,2 +0,2 @@ | ||
// Type definitions for node-cache 4.1 | ||
// Type definitions for node-cache 5 | ||
// Project: https://github.com/tcs-de/nodecache | ||
@@ -10,16 +10,4 @@ // Definitions by: Ilya Mochalov <https://github.com/chrootsu> | ||
/** | ||
* Since 4.1.0: Key-validation: The keys can be given as either string or number, | ||
* but are casted to a string internally anyway. | ||
*/ | ||
type Key = string | number; | ||
type ValueSetItem<T = any> = { | ||
key: Key; | ||
val: T; | ||
ttl?: number; | ||
} | ||
declare namespace NodeCache { | ||
interface NodeCache { | ||
interface NodeCacheLegacyCallbacks { | ||
/** container for cached data */ | ||
@@ -146,2 +134,14 @@ data: Data; | ||
/** | ||
* Since 4.1.0: Key-validation: The keys can be given as either string or number, | ||
* but are casted to a string internally anyway. | ||
*/ | ||
type Key = string | number; | ||
type ValueSetItem<T = any> = { | ||
key: Key; | ||
val: T; | ||
ttl?: number; | ||
} | ||
interface Data { | ||
@@ -152,12 +152,61 @@ [key: string]: WrappedValue<any>; | ||
interface Options { | ||
/** | ||
* If enabled, all values will be stringified during the set operation | ||
* | ||
* @type {boolean} | ||
* @memberof Options | ||
*/ | ||
forceString?: boolean; | ||
objectValueSize?: number; | ||
promiseValueSize?: number; | ||
arrayValueSize?: number; | ||
/** | ||
* standard time to live in seconds. 0 = infinity | ||
* | ||
* @type {number} | ||
* @memberof Options | ||
*/ | ||
stdTTL?: number; | ||
/** | ||
* time in seconds to check all data and delete expired keys | ||
* | ||
* @type {number} | ||
* @memberof Options | ||
*/ | ||
checkperiod?: number; | ||
/** | ||
* en/disable cloning of variables. | ||
* disabling this is strongly encouraged when aiming for performance! | ||
* | ||
* If `true`: set operations store a clone of the value and get operations will create a fresh clone of the cached value | ||
* If `false` you'll just store a reference to your value | ||
* | ||
* @type {boolean} | ||
* @memberof Options | ||
*/ | ||
useClones?: boolean; | ||
errorOnMissing?: boolean; | ||
deleteOnExpire?: boolean; | ||
/** | ||
* enable legacy callbacks. | ||
* legacy callback support will drop in v6.x! | ||
* | ||
* @type {boolean} | ||
* @memberof Options | ||
*/ | ||
enableLegacyCallbacks?: boolean; | ||
/** | ||
* max amount of keys that are being stored. | ||
* set operations will throw an error when the cache is full | ||
* | ||
* @type {number} | ||
* @memberof Options | ||
*/ | ||
maxKeys?: number; | ||
@@ -187,7 +236,10 @@ } | ||
import Data = NodeCache.Data; | ||
import Key = NodeCache.Key; | ||
import Options = NodeCache.Options; | ||
import Stats = NodeCache.Stats; | ||
import Callback = NodeCache.Callback; | ||
import ValueSetItem = NodeCache.ValueSetItem; | ||
import NodeCacheLegacyCallbacks = NodeCache.NodeCacheLegacyCallbacks; | ||
declare class NodeCache extends events.EventEmitter implements NodeCache.NodeCache { | ||
declare class NodeCache extends events.EventEmitter { | ||
/** container for cached data */ | ||
@@ -202,2 +254,3 @@ data: Data; | ||
/** constructor */ | ||
constructor(options?: Options); | ||
@@ -212,4 +265,3 @@ | ||
get<T>( | ||
key: Key, | ||
cb?: Callback<T> | ||
key: Key | ||
): T | undefined; | ||
@@ -224,4 +276,3 @@ | ||
mget<T>( | ||
keys: Key[], | ||
cb?: Callback<{ [key: string]: T }> | ||
keys: Key[] | ||
): { [key: string]: T }; | ||
@@ -241,4 +292,3 @@ | ||
value: T, | ||
ttl: number | string, | ||
cb?: Callback<boolean> | ||
ttl: number | string | ||
): boolean; | ||
@@ -248,4 +298,3 @@ | ||
key: Key, | ||
value: T, | ||
cb?: Callback<boolean> | ||
value: T | ||
): boolean; | ||
@@ -259,3 +308,3 @@ | ||
mset<T>( | ||
keyValueSet: ValueSetItem<T>[], | ||
keyValueSet: ValueSetItem<T>[] | ||
): boolean; | ||
@@ -270,46 +319,32 @@ | ||
del( | ||
keys: Key | Key[], | ||
cb?: Callback<number> | ||
keys: Key | Key[] | ||
): number; | ||
/** | ||
* reset or redefine the ttl of a key. If `ttl` is not passed or set to 0 `stdTtl` is used. if set lt 0 it's similar to `.del()` | ||
* reset or redefine the ttl of a key. If `ttl` is not passed or set to 0 it's similar to `.del()` | ||
*/ | ||
ttl( | ||
key: Key, | ||
ttl: number, | ||
cb?: Callback<boolean> | ||
ttl: number | ||
): boolean; | ||
ttl( | ||
key: Key, | ||
cb?: Callback<boolean> | ||
key: Key | ||
): boolean; | ||
getTtl( | ||
key: Key | ||
key: Key, | ||
): number|undefined; | ||
getTtl( | ||
key: Key, | ||
cb?: Callback<boolean>, | ||
key: Key | ||
): boolean; | ||
/** | ||
* list all keys within this cache | ||
* @param cb Callback function | ||
* @returns An array of all keys | ||
*/ | ||
keys(cb?: Callback<string[]>): string[]; | ||
keys(): string[]; | ||
/** | ||
* Check if a key is cached | ||
* @param key cache key to check | ||
* @param cb Callback function | ||
* @returns Boolean indicating if the key is cached or not | ||
*/ | ||
has(key: Key, cb?: Callback<boolean>): boolean; | ||
/** | ||
* get the stats | ||
@@ -322,4 +357,11 @@ * | ||
/** | ||
* flush the hole data and reset the stats | ||
* Check if a key is cached | ||
* @param key cache key to check | ||
* @returns Boolean indicating if the key is cached or not | ||
*/ | ||
has(key: Key): boolean; | ||
/** | ||
* flush the whole data and reset the stats | ||
*/ | ||
flushAll(): void; | ||
@@ -333,2 +375,3 @@ | ||
export = NodeCache; | ||
export = NodeCache; |
/* | ||
* node-cache 5.0.0-alpha.0 ( 2019-09-18 ) | ||
* node-cache 5.0.0-alpha.1 ( 2019-10-19 ) | ||
* https://github.com/mpneuried/nodecache | ||
@@ -15,4 +15,4 @@ * | ||
exports.version = '5.0.0-alpha.0'; | ||
exports.version = '5.0.0-alpha.1'; | ||
}).call(this); |
/* | ||
* node-cache 5.0.0-alpha.0 ( 2019-09-18 ) | ||
* node-cache 5.0.0-alpha.1 ( 2019-10-19 ) | ||
* https://github.com/mpneuried/nodecache | ||
@@ -65,3 +65,3 @@ * | ||
// myCache.set "myKey", "my_String Value", "10" | ||
// myCache.set "myKey", "my_String Value", 10 | ||
@@ -388,4 +388,4 @@ this.set = this.set.bind(this); | ||
} | ||
// remap the arguments if `ttl` is not passed | ||
if (arguments.length === 3 && typeof ttl === "function") { | ||
// set default ttl if not passed | ||
if (ttl == null) { | ||
ttl = this.options.stdTTL; | ||
@@ -448,3 +448,3 @@ } | ||
del(keys, cb) { | ||
del(keys) { | ||
var delCount, err, i, key, len, oldVal; | ||
@@ -480,17 +480,5 @@ boundMethodCheck(this, NodeCache); | ||
ttl() { | ||
var arg, args, cb, err, i, key, len, ttl; | ||
ttl(key, ttl) { | ||
var err; | ||
boundMethodCheck(this, NodeCache); | ||
// change args if only key and callback are passed | ||
[key, ...args] = arguments; | ||
for (i = 0, len = args.length; i < len; i++) { | ||
arg = args[i]; | ||
switch (typeof arg) { | ||
case "number": | ||
ttl = arg; | ||
break; | ||
case "function": | ||
cb = arg; | ||
} | ||
} | ||
ttl || (ttl = this.options.stdTTL); | ||
@@ -504,3 +492,3 @@ if (!key) { | ||
} | ||
// check for existant data and update the ttl value | ||
// check for existent data and update the ttl value | ||
if ((this.data[key] != null) && this._check(key, this.data[key])) { | ||
@@ -520,3 +508,3 @@ // if ttl < 0 delete the key. otherwise reset the value | ||
getTtl(key, cb) { | ||
getTtl(key) { | ||
var _ttl, err; | ||
@@ -523,0 +511,0 @@ boundMethodCheck(this, NodeCache); |
@@ -28,3 +28,3 @@ { | ||
], | ||
"version": "5.0.0-alpha.0", | ||
"version": "5.0.0-alpha.1", | ||
"author": "mpneuried <mp@tcs.de>", | ||
@@ -56,3 +56,2 @@ "maintainers": [ | ||
"test": "COFFEECOV_INIT_ALL=false mocha --require coffee-script/register --require coffee-coverage/register-istanbul _src/test/mocha_test.coffee -R spec && tsc", | ||
"test-docker": "SILENT_MODE=1 mocha test/mocha_test.js -R min && tsc", | ||
"build": "grunt build" | ||
@@ -59,0 +58,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
53844
1043
0