### Install memoza Source: https://github.com/letstri/memoza/blob/main/README.md Install the memoza package using npm. ```sh npm install memoza ``` -------------------------------- ### Custom Cache Key Derivation Source: https://github.com/letstri/memoza/blob/main/README.md Provide a custom `cacheKey` function to control how cache keys are generated based on arguments. This example uses a string template combining arguments. ```ts const fn = memoize((a: number, b: number) => a + b, { cacheKey: (a, b) => `${a}-${b > 2}`, }) fn(1, 2) // stored fn(1, 5) // stored fn(1, 7) // from cache (same key as above) ``` -------------------------------- ### Basic Usage of memoize Source: https://github.com/letstri/memoza/blob/main/README.md Import and use the `memoize` function for basic memoization. The first call computes the result, while subsequent calls with the same arguments retrieve it from the cache. ```ts import { memoize } from 'memoza' const add = memoize((a: number, b: number) => a + b) add(1, 2) // computed add(1, 2) // from cache ``` -------------------------------- ### Cache Utility Functions Source: https://github.com/letstri/memoza/blob/main/README.md Import and use utility functions like `isMemoized`, `getCacheStore`, and `clearMemoizeCache` to inspect and manage memoized functions and their caches. ```ts import { clearMemoizeCache, getCacheStore, isMemoized } from 'memoza' isMemoized(fn) // true if fn was created with memoize() getCacheStore(fn) // returns { cache, fallbackEntries } or null clearMemoizeCache(fn) // clears all cached entries ``` -------------------------------- ### Promise Support and Automatic Eviction Source: https://github.com/letstri/memoza/blob/main/README.md memoza supports promises. Failed promises are automatically removed from the cache, allowing subsequent calls to retry the operation. ```ts const fn = memoize(async (id: string) => fetchData(id)) await fn('a') // computed await fn('a') // from cache // if the promise rejects, the entry is removed and the next call re-runs ``` -------------------------------- ### Cache Expiration with maxAge Source: https://github.com/letstri/memoza/blob/main/README.md Configure a memoized function to expire cached entries after a specified time in milliseconds using the `maxAge` option. ```ts const fn = memoize(fetchUser, { maxAge: 5000 }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.