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

fix: don't use cache for fetching objects and files by default #272

Merged
merged 12 commits into from
Nov 3, 2021

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Nov 2, 2021

New Pull Request Checklist

Issue Description

When objects or files are being “fetched”, they sometimes leverage the OS level cache and pull from cache if there was a cache hit. This can lead to unintended behavior as when a “fetch” is used, it implies fresh data from the server.

In addition, when caching a file that was downloaded via the SDK, the temporary file location is cached instead the new location the file was moved to. This results in a cache hit, but points to a file location that’s no longer valid.

Related issue: #226

Approach

For "fetching", the default cache policy is set for all ParseObject's and ParseFile's to not use cache. If the developer wants to use cache, they should pass the respective cache policy into options when calling the respective fetch method. The default cache policy for the SDK can be changed by the developer if needed:

/// The default caching policy for all http requests that determines when to
/// return a response from the cache. Defaults to `useProtocolCachePolicy`.
/// See Apple's [documentation](https://developer.apple.com/documentation/foundation/url_loading_system/accessing_cached_data)
/// for more info.
var requestCachePolicy = URLRequest.CachePolicy.useProtocolCachePolicy

When fetching ParseFile, cache the final location the file was moved to instead of the temporary location

TODOs before merging

  • Add tests
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)

@parse-github-assistant
Copy link

parse-github-assistant bot commented Nov 2, 2021

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #272 (c0f8043) into main (a64726f) will decrease coverage by 0.09%.
The diff coverage is 87.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #272      +/-   ##
==========================================
- Coverage   82.34%   82.25%   -0.10%     
==========================================
  Files         102      102              
  Lines       10525    10575      +50     
==========================================
+ Hits         8667     8698      +31     
- Misses       1858     1877      +19     
Impacted Files Coverage Δ
...Authentication/Protocols/ParseAuthentication.swift 70.98% <ø> (ø)
Sources/ParseSwift/LiveQuery/Subscription.swift 68.35% <ø> (ø)
...es/ParseSwift/LiveQuery/SubscriptionCallback.swift 93.75% <ø> (ø)
...s/ParseSwift/Objects/ParseInstallation+async.swift 100.00% <ø> (ø)
...ParseSwift/Objects/ParseInstallation+combine.swift 100.00% <ø> (ø)
Sources/ParseSwift/Objects/ParseObject+async.swift 100.00% <ø> (ø)
...urces/ParseSwift/Objects/ParseObject+combine.swift 100.00% <ø> (ø)
Sources/ParseSwift/Objects/ParseUser+async.swift 100.00% <ø> (ø)
Sources/ParseSwift/Objects/ParseUser+combine.swift 100.00% <ø> (ø)
Sources/ParseSwift/Types/ParseAnalytics.swift 98.13% <ø> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a64726f...c0f8043. Read the comment docs.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Nov 2, 2021

@vdkdamian can you try out this branch? Note that it will only fix your problem if was related to the caching I mentioned in #226 (comment) and #226 (comment). If this doesn't fix your issue, then you will have to look in other places in your code and SDK.

@vdkdamian
Copy link
Contributor

@cbaker6 This solves my issue! I tested it multiple times on iOS, then multiple times on macOS. Everything is working fine for me now.

@cbaker6 cbaker6 changed the title fix: don't use cache for fetching objects or files by default fix: don't use cache for fetching objects and files by default Nov 2, 2021
@cbaker6 cbaker6 linked an issue Nov 3, 2021 that may be closed by this pull request
7 tasks
@cbaker6 cbaker6 merged commit 72eb7c5 into main Nov 3, 2021
@cbaker6 cbaker6 deleted the fetchFileBug branch November 3, 2021 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong image data when fetching image
2 participants