Skip to content

Multiple cache keys #3583

@wvteijlingen-npo

Description

@wvteijlingen-npo

Question

Currently, SchemaConfiguration.cacheKeyInfo supports returning only a single CacheKeyInfo instance per object. As a result, each object can be cached using only one cache key. This works perfectly fine when reading cached objects using ApolloStore.withinReadTransaction { transaction in transaction.readObject(...) }

However, would it be possible to somehow support multiple cache keys per object?

I’ve experimented with a custom NormalizedCache that manually splits and joins the cache key strings to work around this limitation, but the approach feels like a hack and is not reliable at all.

Background

In our GraphQL schema some models have multiple unique identifiers. For example, a User has both an id and an urn. Due to legacy reasons, different parts of our application reference users by either id or urn.

Because the cache can only recognize one of these keys, we often have cache misses. This forces us to query the GraphQL endpoint even though technically the User object does exist in the cache.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that have a question which should be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions