This section covers several functions from the library that help manage caching and memoization in your application.
cachedFunction
Memoizes a function with effects, caching results for the same inputs to avoid recomputation.
Example (Memoizing a Random Number Generator)
once
Ensures an effect is executed only once, even if invoked multiple times.
Example (Single Execution of an Effect)
cached
Returns an effect that computes a result lazily and caches it. Subsequent evaluations of this effect will return the cached result without re-executing the logic.
Example (Lazy Caching of an Expensive Task)
cachedWithTTL
Returns an effect that caches its result for a specified duration, known as the timeToLive. When the cache expires after the duration, the effect will be recomputed upon next evaluation.
Example (Caching with Time-to-Live)
cachedInvalidateWithTTL
Similar to Effect.cachedWithTTL, this function caches an effect’s result for a specified duration. It also includes an additional effect for manually invalidating the cached value before it naturally expires.