Optional
options: CacheItOptions<any>Optional
5.16.0
// set max cache size
const f = cacheIt((value: number) => (++idx) + value, {
providerOptions: {
params: {
max_entries: 2
}
}
});
expect(f.__cache_storage["_maxSize"]).toBe(2);
expect(f(0)).toBe(1);
expect(f(0)).toBe(1);
create a class wrapper, the instance created by that wrapper will automatically apply cacheIt
Optional
options: CacheItOptions<any>Optional
5.16.0
class A {
constructor(idx = 0) { this.idx = idx; }
private idx: number
public add(value: number) {
return (++this.idx) + value;
}
}
const CachedA = cacheIt(A);
const a = new CachedA(1);
expect(a.add(0)).toBe(2);
expect(a.add(0)).toBe(2);
expect(a.add(1)).toBe(4);
expect(a.add(1)).toBe(4);
make function is cached, default with LRU container
Optional
options: CacheItOptions<any>Optional
5.16.0
Optional
options: CacheItOptions<any>Optional
make all methods of object are cached