Implementing Sequential Data Source Queries with Caching in Effect Typescript
Hi, I’m looking for guidance on implementing the following pattern:
The problem:
- I have multiple data sources that accept the same query type.
- For a given query, I want to request data from all sources sequentially until the first one successfully returns a result.
- There are multiple queries running in parallel, and I want cache the result to reduce load on data sources. Thus I need the cache to be per data source
I’ve implemented each data source as a
I was thinking that adding an extra field, like type, to the
Is there a better way to approach this pattern?
The problem:
- I have multiple data sources that accept the same query type.
- For a given query, I want to request data from all sources sequentially until the first one successfully returns a result.
- There are multiple queries running in parallel, and I want cache the result to reduce load on data sources. Thus I need the cache to be per data source
I’ve implemented each data source as a
RequestResolver with the same Request type. To iterate over the data sources, I used Effect.validateFirst. But later I realized that RequestResolver caches based on the request key. This means only the first RequestResolver executes, and others return the cached value instead of being called.I was thinking that adding an extra field, like type, to the
Request to make each request unique can fix it. But that made me wonder if I’m misusing the Request. Is there a better way to approach this pattern?
