J’aime beaucoup Simon Willison depuis des années. Il tient un carnet de notes en guise de blog, comme j’aurais longtemps voulu avoir le courage de faire.
Il relaie là un commentaire ycombinator :
When caching the result of an expensive computation or a network call, don’t actually cache the result, but cache the promise that awaits the result.
This way, if a new, uncached key gets requested twice in rapid succession, ie faster than the computation takes, you avoid computing/fetching the same value twice. […] In other words, the promise acts as a mutex around the computation, and the resulting code is understandable even by people unfamiliar with mutexes, locks and so on.
Laisser un commentaire