When instantiating a Resource, Siesta checks for cached data asynchronously, updating the resource later if there is a cache hit (and if the resource hasn’t loaded fresh data in the meantime). This is good, but it creates a race condition where loadIfNeeded may initiate a network request if called before the cache check is done.
Instead, loadIfNeeded() should return a chained request that first waits for the cache check if there is one in progress, and only chains to the a network request if the we got a cache miss.
(Original SO question)
When instantiating a
Resource, Siesta checks for cached data asynchronously, updating the resource later if there is a cache hit (and if the resource hasn’t loaded fresh data in the meantime). This is good, but it creates a race condition whereloadIfNeededmay initiate a network request if called before the cache check is done.Instead,
loadIfNeeded()should return a chained request that first waits for the cache check if there is one in progress, and only chains to the a network request if the we got a cache miss.(Original SO question)