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

Shouldn't the default cache folder be /library or /documents not /library/caches? #179

Closed
RamblinWreck77 opened this issue Apr 8, 2018 · 9 comments

Comments

@RamblinWreck77
Copy link

RamblinWreck77 commented Apr 8, 2018

So I've been chasing a weird issue and I think I've gotten to the bottom of it. My app launches in the background periodically and I need to recover user data. After some logging it appeared my users were being logged out way too often/not having user credentials frequently.

So keychain periodically (~5%) of the time fails in the background (longstanding iOS issue), so I store a backup copy in cache to catch it.

Thing is, periodically cache fails too (with a not-found error for a user that definitely exists, and successfully wrote some info to disk)

I discovered that the default directory is Library/Caches, and according to:

https://stackoverflow.com/questions/7155964/will-application-home-library-caches-be-clear-on-app-update

and various other places iOS can periodically clear those files.

This seems counter-intuitive as I would expect most devs to expect a .never expiry to not be at risk of deletion from the OS itself.

All in all it's not a big deal to switch to /Documents (it's nice that this will be backed up by itunes/icloud... library/caches is not!) I am wondering if a change to the default location wouldn't make sense.

Thanks for such a great tool!

Edit: For those who find this later, the correct folder for this is Library/Application Support. I will update this post if moving to this folder solves my issue. I have a build rolling out now that uses the new location so I will see if this fixes my primary issue.

@IgorBulyga
Copy link

IgorBulyga commented Apr 8, 2018

@RamblinWreck77 Hi!

Using Documents directory to store cache files is not good idea, because if you will enable iTunes File Sharing Option in you application user will see your caches files. However apple provided another directory for storing application related files which is also will be backed up in iCloud - Library/Application Support. Just create here folder for your data and store them.

@RamblinWreck77
Copy link
Author

Awesome! Thanks for the quick reply @IgorBulyga ! This folder should persist for application updates and be available in the background right?

@john1452
Copy link

john1452 commented Apr 9, 2018

ah this seems to be same issue that I am having #180
I expected the .never expiry to never delete the folder. Maybe the default path should change?

Question: Library/Application safe to store user sensitive information? Such user phone number, email address etc?

@IgorBulyga
Copy link

@RamblinWreck77 Yes, like Apple Documentation says

Put app-created support files in the Library/Application support/ directory. In general, this directory includes files that the app uses to run but that should remain hidden from the user. This directory can also include data files, configuration files, templates and modified versions of resources loaded from the app bundle. Remember that files in Documents/ and Application Support/ are backed up by default.

@john1452 I suppose it would be safe BUT it would be better to store user sensitive data in keychain.

@RamblinWreck77
Copy link
Author

@IgorBulyga Keychain was my initial go-to for recovering user fingerprints.

The issue is keychain has serious problems when in the background (see evgenyneu/keychain-swift#15)

At my scale tens of thousands of sessions a day fail to recover their user session data while in the background, hence using cache as a backup for that scenario.

@RamblinWreck77
Copy link
Author

Update: I've had this fix out for ~2 weeks now and am not seeing a drop off in background file-not-found.

I'm at a loss for what could be causing this...

@onmyway133
Copy link
Contributor

@RamblinWreck77 Hi, I 've made a refactoring here #189 and address your issue. You can still use DiskConfig to customise directory path, and from now on, document directory is used by default

@IgorBulyga
Copy link

@onmyway133 Hi, I suppose it is not good idea. Because Documents directory is used for user information and it could be visible to user if application supports iTunes File Sharing, besides now cache folder will be changed folder for applications which are using library and they will recache everything what was cached.

Maybe it would be better leave cache directory by default and who will not want use it could change it in config?

@onmyway133
Copy link
Contributor

@IgorBulyga After discussion, I think you're right. We will use Cache directory for now

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

No branches or pull requests

4 participants