@mantlebee/ts-data
    Preparing search index...

    Function withCache

    • Memoizes the item of each resolved value for the life of the source, so a department shown in twenty rows and on every page is asked once: a resolve sends the inner source only the values it has never seen, a value being resolved is shared by every caller asking for it meanwhile, a value the inner source does not return is remembered as missing, and a rejected resolution is forgotten, so the next call tries again. ICachedLookupSource.invalidate forgets entries by hand. search and valueOf are untouched.

      Signal. The call of the inner source runs without a signal: its result fills the cache even for a caller that no longer wants it, and one caller's abort must not starve the others sharing the resolution. The aborted caller alone rejects with AbortedException, at once.

      Compose it outside withBatching, withCache(withBatching(source)): the misses of the cache are what the batch coalesces.

      Type Parameters

      • TItem

        Type of the items.

      • TValue

        Type of the key of an item.

      Parameters

      Returns ICachedLookupSource<TItem, TValue>

      a source with the same contract, caching resolve, plus invalidate.

      const departments = withCache(withBatching(createLookupSource(readDepartments, { textField: "name", valueField: "id" })));
      await departments.resolve([1, 2]); // one request
      await departments.resolve([2, 3]); // one request, for 3 only
      departments.invalidate([2]); // 2 is asked again next time