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

Feature Request: Cache invalidation methods #166

Open
apackin opened this issue Aug 17, 2022 · 1 comment
Open

Feature Request: Cache invalidation methods #166

apackin opened this issue Aug 17, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@apackin
Copy link

apackin commented Aug 17, 2022

Currently to invalidate a cached query I'm doing:

   invalidateCachedQuery(queryDocument) {
    final cacheQueries = _store.get('Query');
    if (cacheQueries == null) return;
    final cachedNodeDefinition = queryDocument.definitions.whereType().first;
    final topLevelSelectionSet = cachedNodeDefinition?.selectionSet?.selections;
    topLevelSelectionSet.forEach((selection) {
      final cacheKey = selection.name.value;
      if (cacheKey != '__typename' && cacheQueries.containsKey(cacheKey)) {
        cacheQueries.remove(cacheKey);
      }
    });
  }
  
  invalidateCachedQuery$GetState() {
    invalidateCachedQuery(documentNodeQueryGetState);
  }

It would be great if there was a shorthand like client.invalidateQuery$GetState() that handled this for all queries.

@budde377 budde377 added the enhancement New feature or request label Aug 28, 2022
@apackin
Copy link
Author

apackin commented Aug 29, 2022

I updated the example code based on #173, looks like they're trying to accomplish a similar goal of flagging cached queries as invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants