useCache Method

Enables caching, allowing the results of the asynchronous action to be stored and reused based on certain conditions. The cache can be configured to expire after a specified lifetime or to be used conditionally based on a callback function

@param secOrFn: number | (() => boolean)
The lifetime of the cache in seconds, or a callback function that returns a boolean value. If the callback returns true, the cache will be used

@param cacheSize = 10
The maximum number of entries in the cache. If the cache size exceeds this limit, the earliest entries will be deleted following a FIFO strategy

API

useCache(secOrFn: number | (() => boolean), cacheSize = 10): this;

Example

import {asyncSignalGroup} from '@bitfiber/ng/rx';
 
// Creates an asynchronous group
const group = asyncSignalGroup<number, string[], Error>(group => {
  group
    // Keeps cached data for 60 seconds, with a maximum entry count of 5
    .useCache(60, 5);
});