---
title: "Discussion on \"F# tips weekly #16: Asynchronous memoize\" | Hashnode"
description: "Discussion on \"F# tips weekly #16: Asynchronous memoize\". Caching the results of asynchronous functions is a common task. Can we use memoize for it? Let's find out!\nMemoized Task\nSurprisingly, task works great with the basic memoize function from Tip #14. If we use a function that returns Task<_>, we get a ..."
url: "https://hashnode.com/posts/f-tips-weekly-16-asynchronous-memoize/665807f943081a3c1a1ac2e8"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [F# tips weekly #16: Asynchronous memoize](https://jindraivanek.hashnode.dev/f-tips-weekly-16-asynchronous-memoize?utm_source=hashnode&utm_medium=feed)

Caching the results of asynchronous functions is a common task. Can we use memoize for it? Let's find out! Memoized Task Surprisingly, task works great with the basic memoize function from Tip #14. If we use a function that returns Task<\_>, we get a ...

May 30, 2024 · 3 min read · jindraivanek.hashnode.dev  
Updated Jul 22, 2024  
Read the article

-   [#f](https://hashnode.com/tag/f)
-   [#fsharp](https://hashnode.com/tag/fsharp)
-   [#tips](https://hashnode.com/tag/tips)
-   [#memoization](https://hashnode.com/tag/memoization)

## Written by

[Jindřich Ivánek](https://hashnode.com/@jindraivanek)

@jindraivanek · Prague, Czech Republic

  
[View profile](https://hashnode.com/@jindraivanek)

F# developer

Software developer focused mainly on F#, with a passion for functional programming, problem solving, efficient algorithms and programming languages. I have a strong computer science background, focused mainly in graph theory and graph algorithms; also was intrigued by data structures, complexity, and computability theory. Experienced with backend F# programming. I worked with mathematical optimization (mixed integer programming) and use of statistical methods as well. I contributed to several open source F# projects, mostly around developer tooling.

## Responses 1

Markdown supported · ⌘↵ to post

[Ruben Bartelink](https://hashnode.com/@bartelink)

[Jun 26, 2024](https://hashnode.com/posts/f-tips-weekly-16-asynchronous-memoize/665807f943081a3c1a1ac2e8/comment/667c9ddb41398ce443dea7ff)

Re your question about there being a simpler way of memoizing a Task and/or Async - it's not trivial, but Simple is not Easy either...

TaskCell, a helper in Equinox covers memoization of a Task, with expiration (and not caching failures): github.com/jet/equinox/blob/master/src/Equinox.Core/TaskCell.fs

See the tests in the repo for the semantics

The helper is used a) internally in the Equinox caching system (not dissimilar to the stampede prevention in the .NET 9 IDistributedCache impl) b) as a standalone construct (e.g. it can be used to ensure you have a live token for some third party API given some validity period, with only a single update call regardless of how many callers trigger it etc)
