Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorter operation cache keys #400

Closed
micimize opened this issue Aug 30, 2019 · 4 comments
Closed

Shorter operation cache keys #400

micimize opened this issue Aug 30, 2019 · 4 comments
Labels
📦 cache Relates to caching functionality

Comments

@micimize
Copy link
Collaborator

micimize commented Aug 30, 2019

Operation cache keys are very long (full document + variables)

We should consider making keys a hash or uuid. Not a hashCode though 😬

Objects that are not equal are allowed to have the same hash code

@micimize
Copy link
Collaborator Author

@lookfirst moving discussion here.

One option would be to use uuid.v5 for deterministic uuids. Maybe something like $documentUuid/$operationName($variables)

I guess apollo just caches by $operationName($variables) (I guess they don't support anonymous operations):
image

@klavs
Copy link
Collaborator

klavs commented Oct 7, 2019

@micimize I think in Apollo it is actually

[GraphQLType]: {
  field(variables): value
}

And then the same goes recursively down per value. At least for the in-memory de-normalized cache it is so. Maybe some less advanced cache implementation cares about unique operation keys, because it caches the whole responses instead of every entity.

I think this API is limiting
https://github.com/zino-app/graphql-flutter/blob/519381cd1c57515fd26cedb33c68a68d563a6eac/packages/graphql/lib/src/cache/cache.dart#L1-L7

Instead of reading and writing with a key, we should read/write with a whole qurey+variables then it's cache's responsibility to come up with their own key.
Also, the de-normalizing cache will need the query document + variables to determine what arguments were used on a field. It cannot do it only by looking at the response data.

@lookfirst
Copy link
Contributor

There is also @connection to consider. Some times, you don't want every variable cached as it would pollute the cache and make it totally ineffective. Imagine sorting a table of data on the server. You don't want to cache by sort key. Took me a bit to figure this out.

@klavs klavs added the 📦 cache Relates to caching functionality label Feb 18, 2020
@micimize
Copy link
Collaborator Author

micimize commented Oct 7, 2020

closed in v4 by using normalize #648

@micimize micimize closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 cache Relates to caching functionality
Projects
None yet
Development

No branches or pull requests

3 participants