-
Notifications
You must be signed in to change notification settings - Fork 130
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
Cache doesn't seem to work when performing a query which maps to dynamoDB secondary index (i.e. not doing a query based on "id") #165
Comments
I think I've discovered the issue. For this particular object type I'm using an email address as the AppSync ID, and so this is then used as the cache key by apollo. However it looks like the apollo cache doesn't like the cache key to contain to contain "@" or ".". I'll dig into this more tomorrow. |
Thanks for the update @mrbarnaby.
Are you basing this on an inspection of the Apollo code, or on your observations of behavior? |
@mrbarnaby @palpatim I have encountered the same issue where the cache key contains a ".". For example I tested another scenario with String. Therefore, in both cases, it will return nil when fetching queries from cache in offline mode. Can you help to take a look? |
Thanks for the comments and explanation of your use case. I'll take a look. |
Based on my read of the code, the Unfortunately, I'm not sure what to do for a workaround at this point, and will have to consider this. We may need to allow an option for replacing the path separator for nested objects. Once we fix that, we'll need to update the docs to call this out. |
Hi, I am experiencing the same issue with the
The problem appears when AWSSQLiteNormalizedCache tries to merge records and fails to obtain the fieldCacheKey: Expected recordCacheKey above is After some digging I found out the recordCacheKey is extracted by splitting the fieldCacheKey by To work around this I implemented a different way for extracting the recordCacheKey. I'm trying to figure out if a
Now the recordCacheKey Counting parentheses should also work if cache key is composed recursively, but I haven't tested. This works for emails or float values because they don't contain parentheses. It doesn't always work when String params are used which can contain |
Thanks for diving into this. I'm looking at this and will update when I have more info. |
- Fix optimistic update tests to wait for optimistic update to complete before fetching - Added unit test helper for some utility functions - Ported Apollo's CachePersistenceTests from their HEAD - Added new field, 'friendsFilteredById', to allow easier testing of arguments with arbitrary string constructions - Added persistence tests for arguments with dots
- Fix optimistic update tests to wait for optimistic update to complete before fetching - Added unit test helper for some utility functions - Ported Apollo's CachePersistenceTests from their HEAD - Added new field, 'friendsFilteredById', to allow easier testing of arguments with arbitrary string constructions - Added persistence tests for arguments with dots
#186 should resolve the issue with using dots in cache keys Discussion This problem actually exists in the SQLite normalized cache implementation we forked from Apollo. The solution I've put in place caches incoming records by composing a list of "candidate record keys" based on the changed keys. If the candidate keys exist in the incoming changed records, the cache will be updated with the new value. This has the downside of a larger number of comparisons, but should catch cases where the cache key includes dots as part of the argument chain, including cases like I'm not thrilled with this implementation. I also explored using a different cache path delimiter, but any of those solutions are susceptible to collisions. Even using non-printing characters has problems with debugging usability/logging. The right thing to do here is probably to change the results of the "changed cache key" to be something like a "changed cache paths", so that path elements are clearly delimited. However, that was going to be a pretty far-reaching change, and more than I was comfortable taking on for this fix. |
- Fix optimistic update tests to wait for optimistic update to complete before fetching - Added unit test helper for some utility functions - Ported Apollo's CachePersistenceTests from their HEAD - Added new field, 'friendsFilteredById', to allow easier testing of arguments with arbitrary string constructions - Added persistence tests for arguments with dots
- Fix optimistic update tests to wait for optimistic update to complete before fetching - Added unit test helper for some utility functions - Ported Apollo's CachePersistenceTests from their HEAD - Added new field, 'friendsFilteredById', to allow easier testing of arguments with arbitrary string constructions - Added persistence tests for arguments with dots
This is released on 2.10.2. Please let us know if you continue to experience problems. |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
In my iOS project I'm using AppSync and DynamoDB.
The AppSync cache is working fine for me on 4 out of the 5 queries I'm using. However it isn't working on the 5th query and I'm not sure why. I can't figure it out.
The main difference with the 5th query is that the first 4 queries are standard "List with Filter (aka DynamoDB scan)" or "Get with Id (aka Dynamo query by id)", however with the 5th query I'm doing a query based on an attribute in a secondary index in DynamoDB. I've written a custom resolver in AppSync which maps to this attribute (it uses a DynamoDB 'query' not a 'scan'). The query works fine... the custom "User" objects which I'm requesting are returned as expected. However they never end up in the Apollo cache.
Any help would be greatly appreciated as not being able to retrieve the User object from the cache is breaking the offline behaviour of my app completely!
Debug I've tried so far
Code snippets
I believe I'm calling the problematic query in a standard way.
This one does cache successfully:
appSyncClient?.fetch(query: GetUserQuery(id: userId), cachePolicy: cachePolicy) { (result, error) in
This one doesn't cache:
appSyncClient?.fetch(query: GetUsersByCanonicalEmailQuery(canonicalEmail: canonicalEmail, limit: 10), cachePolicy: cachePolicy) { (result, error) in
Environment(please complete the following information):
Device Information (please complete the following information):
The text was updated successfully, but these errors were encountered: