NewDash

    Function cacheIt

    • make all methods of object are cached

      Type Parameters

      Parameters

      Returns CachedFunction<T>

      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

      Type Parameters

      Parameters

      Returns CachedClass<T>

      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

      Type Parameters

      • T extends object

      Parameters

      Returns CachedObject<T>

      5.16.0

    • make all methods of object are cached

      Type Parameters

      • T extends object

      Parameters

      Returns CachedObject<T>

      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);
    MMNEPVFCICPMFPCPTTAAATR