Create a per-user cache of suggested edits tasks, populate it on user creation, and refresh it each time tasks are fetched (via visits to Special:Homepage or through toggling task/topic filters).
Caching is tricky because 1) there are many permutations on task types & topics, 2) we don't want to show every user the same thing, 3) we don't want to show stale task recommendations to users.
Given the above, I would propose we use caching to optimize the loading of Special:Homepage, and not the in-module interactions (toggling difficulty / topic filters). Improved performance when toggling filters will in part be handled by T242560 in any case.
The approach would be roughly:
* user creates account and is opted into the experiment, in the same request we make a request to get a set of suggested edits (as if they had visited Special:Homepage and opted in to suggested edits, so we'd use the default values of copyedit+links and no topics) and cache it for that user for 730 days
* when the user visits Special:Homepage, the code which fetches suggested edits first looks to see if there is data in the cache for the current set of filters (e.g. copyedit+links), and if so loads it, if not it asks ElasticSearch for it. After getting it from ElasticSearch, we cache it again for 730 days.
If we are concerned about stale data being presented to* When the user, we could also load the initial card(s) from the cache requests tasks, and once the background request to ElasticSearch compleuse a DB query to validate that the relevant maintenance templates (somewhere between 1 and dozens of seconds,are still present in the cached tasks; depending on filter selections) we could silently swap in the fresh data in the suggested edits module task queue.
We can also validate the results with a single DB query to check to see if the relevant maintenance templates are still present for the article IDs before returning them to the user.remove tasks from the cache which no longer have the maintenance templates
* on each change to the users task/topic filter preferences, recache the data