Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Different TTL for queries and objects in the cache #88

@tolmachev21

Description

@tolmachev21

Hi guys! Thank you very much for the opportunity to use this library. I would be very grateful if you could help me with the following problem :)

Minimum context:

I want to use the following invalidationPolicy configuration settings:

invalidationPolicies: {
        timeToLive: 15 * 60 * 1000, // 15 minutes in milliseconds
        types: {
            User: {
                timeToLive: 60 * 1000, // 1 minute in milliseconds
            },
        },
    }

It turns out that queries inside ROOT_QUERY will live for 15 minutes. And the cached objects themselves will live for one minute.

Problem description (page and query names are used as an example only):

  1. I go to the /user page, which uses the getUser query. When it is executed, the query itself (i.e. getUser) and the response of this query (i.e. the User object itself) are cached.

  2. Then I wait one minute for the User object in the cache to become invalid (i.e. the TTL has expired). It is worth noting that the getUser query is still valid.

  3. I go to the page /. At this point, the getUser query remains in the cache inside ROOT_QUERY, but the cached User object is not there (it was deleted because it was invalid).

  4. I go back to the page /user within 15 minutes. And now I have no data on the page, because the ROOT_QUERY still contains broken links to objects in the cache, which are no longer in this cache!

Expected behavior:

First, I would like to clarify whether this behavior is expected?
If yes, what would you recommend me to avoid this behavior.
If not, what option is better to use:

  1. Check object references in ROOT_QUERY for null / undefined? (but as I understand - you need to go to Apollo Client with this question)
  2. Delete query objects (or reference objects themselves) when deleting entities whose TTL has expired?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions