Change API to take the loader, and add tests. Passing in the loader object rather than a boolean should clarify flow. Can also standardize on throwing instead of returning false,
- How will this make life better?
Clearer code path
- How big is this change (small/med/large/really large)?
Small
Medium. Code exists and works, but IMO is hard to follow.
Dependency inject for unit testing to simulate cache fall through.
e.g:
async function load(params, loader) { ... }
async function loadCache(params) {
if (isLocal) {
try {
let result = await load(params, localLoader)
return result
}
catch {
... cache miss
}
}
// S3 load
try {
let result = await load(params, S3Loader)
return result
}
catch {
... failure
}
}