Skip to content

Datafile Cache Location #485

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

Closed
rhys-rant opened this issue Mar 23, 2023 · 3 comments
Closed

Datafile Cache Location #485

rhys-rant opened this issue Mar 23, 2023 · 3 comments

Comments

@rhys-rant
Copy link

Hi there!

Is there any way to configure the location of the cached datafile?

Currently it seems to store to the application's Documents folder, which seems inappropriate when there's a Caches directory on iOS. If an app opens itself to the Files app, it will also expose the datafile via the Documents folder, meaning end users will see that datafile.

Ideally, the SDK should default to storing a cached datafile in the Caches directory, or allow the user to configure where to store it.

If this functionality exists in the SDK, I'd really appreciate some pointers on what I need to configure! Thanks :)

@jaeopt
Copy link
Contributor

jaeopt commented Mar 23, 2023

@rhys-rantmedia Thanks for reporting. Currently there is no easy way to override the location. We'll look into it.
https://jira.sso.episerver.net/browse/FSSDK-9013

@russell-loube-optimizely

Hi @rhys-rantmedia, thanks for your patience on this. We have just pulled a spike research story into our current sprint to identify potential solutions to allow configuration of the datafile cache location. We'll keep you posted here.

@russell-loube-optimizely
Copy link

russell-loube-optimizely commented May 24, 2023

Hi again @rhys-rantmedia , some findings below.

The Caches directory is only for temporary storage and iOS clears this cache anytime the app runs out of memory. This is the main reason why we are saving the datafile in the Documents directory, which is permanent storage and not subject to automatic deletion by iOS in periods of high memory consumption.

It is possible to supply your own OPTDatafileHandler interface with the following methods:

func saveDatafile(sdkKey: String, dataFile: Data)

func loadSavedDatafile(sdkKey: String) -> Data?

func isDatafileSaved(sdkKey: String) -> Bool

func removeSavedDatafile(sdkKey: String)

If desired, you can use our default datafile handler class and override the above methods to store and retrieve the datafile in a customized manner.

For tvOS and macOS, we do use the cache directory as seen in the below code snippet:

#if os(tvOS) || os(macOS)

let directory = FileManager.SearchPathDirectory.cachesDirectory

#else

let directory = FileManager.SearchPathDirectory.documentDirectory

#endif

I hope the above helps somewhat. Please let us know if you're able to move forward with such an approach, or if there's any other information we can provide to assist. Thanks!

@jaeopt jaeopt closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants