A simple way to keep a query in the cache fetched with only the latest set of variables, and discard the rest?

Let’s say I have a query with a variable that I use inside a useQuery hook:

translations(localeCode: $localeCode): ...

I’m looking for a solution that meets the following requirements:

  • cache-and-network fetch policy can be used, so the result is read from the cache and stored in the cache;
  • when localeCode variable changes, the previous data (associated with another variable value) is deleted (so if the variable takes the old value again, it’s not available in the cache anymore).

I know that I can set nextFetchPolicy: "network-only", but then the 2nd requirement would not be met as noticed when my component remounts. Also the cache would still store unnecessary data.

So far I was only able to partially achieve this with manual cache manipulation with cache.evict. I’m wondering if there’s a cleaner solution because this seems like a common use case.

Any help appreciated!