mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
memory-cache: Add type parameters and expose constructor to instantiate new caches (#20501)
* memory-cache: Add type parameters and expose constructor to instantiate new caches * Return arrays from keys() function * Extend dtslint and fix linting errors * Add version 0.2 to type header
This commit is contained in:
Vendored
+29
-12
@@ -1,20 +1,37 @@
|
||||
// Type definitions for memory-cache
|
||||
// Type definitions for memory-cache 0.2
|
||||
// Project: https://github.com/ptarjan/node-cache
|
||||
// Definitions by: Jeff Goddard <https://github.com/jedigo>
|
||||
// Travis Thieman <https://github.com/thieman>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
// Imported from: https://github.com/soywiz/typescript-node-definitions/memory-cache.d.ts
|
||||
// Originally imported from: https://github.com/soywiz/typescript-node-definitions/memory-cache.d.ts
|
||||
|
||||
export class CacheClass<K, V> {
|
||||
put(key: K, value: V, time?: number, timeoutCallback?: (key: K, value: V) => void): V;
|
||||
get(key: K): V;
|
||||
del(key: K): void;
|
||||
clear(): void;
|
||||
|
||||
export declare function put(key: any, value: any, time?: number, timeoutCallback?: (key: any, value: any) => void): void;
|
||||
export declare function get(key: any): any;
|
||||
export declare function del(key: any): void;
|
||||
export declare function clear(): void;
|
||||
size(): number;
|
||||
memsize(): number;
|
||||
|
||||
export declare function size(): number;
|
||||
export declare function memsize(): number;
|
||||
debug(bool: boolean): void;
|
||||
hits(): number;
|
||||
misses(): number;
|
||||
keys(): K[];
|
||||
}
|
||||
|
||||
export declare function debug(bool: boolean): void;
|
||||
export declare function hits(): number;
|
||||
export declare function misses(): number;
|
||||
export declare function keys(): any;
|
||||
export const Cache: typeof CacheClass;
|
||||
|
||||
export function put<V>(key: any, value: V, time?: number, timeoutCallback?: (key: any, value: any) => void): V;
|
||||
export function get(key: any): any;
|
||||
export function del(key: any): void;
|
||||
export function clear(): void;
|
||||
|
||||
export function size(): number;
|
||||
export function memsize(): number;
|
||||
|
||||
export function debug(bool: boolean): void;
|
||||
export function hits(): number;
|
||||
export function misses(): number;
|
||||
export function keys(): any[];
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
|
||||
import memoryCache = require('memory-cache');
|
||||
|
||||
var key: any;
|
||||
var value: any;
|
||||
var bool: boolean;
|
||||
var num: number;
|
||||
const key: any = 'sampleKey';
|
||||
let value: string;
|
||||
const bool = false;
|
||||
let num: number;
|
||||
let returnedValue: string;
|
||||
|
||||
memoryCache.put(key, value);
|
||||
memoryCache.put(key, value, num);
|
||||
memoryCache.put(key, value, num, (key) => {
|
||||
returnedValue = memoryCache.put(key, value);
|
||||
returnedValue = memoryCache.put(key, value, num);
|
||||
returnedValue = memoryCache.put(key, value, num, (key) => { });
|
||||
returnedValue = memoryCache.put(key, value, num, (key, value) => { });
|
||||
|
||||
});
|
||||
memoryCache.put(key, value, num, (key, value) => {
|
||||
|
||||
});
|
||||
value = memoryCache.get(key);
|
||||
memoryCache.del(key);
|
||||
memoryCache.clear();
|
||||
@@ -24,3 +21,14 @@ num = memoryCache.memsize();
|
||||
memoryCache.debug(bool);
|
||||
num = memoryCache.hits();
|
||||
num = memoryCache.misses();
|
||||
|
||||
const customCache = new memoryCache.Cache<string, boolean>();
|
||||
|
||||
const customKey = 'customKey';
|
||||
let customValue: boolean;
|
||||
let customKeys: string[];
|
||||
|
||||
customValue = customCache.put(customKey, customValue);
|
||||
customCache.get(customKey);
|
||||
customCache.del(customKey);
|
||||
customKeys = customCache.keys();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user