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

**URL:** <https://community.apollographql.com/t/a-simple-way-to-keep-a-query-in-the-cache-fetched-with-only-the-latest-set-of-variables-and-discard-the-rest/7394>\
**Category:** Client SDKs\
**Tags:** client\
**Created:** [April 17, 2024, 1:15pm UTC](https://community.apollographql.com/t/a-simple-way-to-keep-a-query-in-the-cache-fetched-with-only-the-latest-set-of-variables-and-discard-the-rest/7394 "2024-04-17T13:15:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimpleCreations](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/simplecreations/32/4599_2.png) [@SimpleCreations](https://community.apollographql.com/u/SimpleCreations)\
**Post date:** [April 17, 2024, 1:15pm UTC](https://community.apollographql.com/t/a-simple-way-to-keep-a-query-in-the-cache-fetched-with-only-the-latest-set-of-variables-and-discard-the-rest/7394/1 "2024-04-17T13:15:00Z")

</div>

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

```auto
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!
