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

clearCache for SQLiteNormalizedCache doesn't clear the sqlite file #3389

Closed
avielg opened this issue Jun 6, 2024 · 3 comments
Closed

clearCache for SQLiteNormalizedCache doesn't clear the sqlite file #3389

avielg opened this issue Jun 6, 2024 · 3 comments
Labels
awaiting response bug Generally incorrect behavior

Comments

@avielg
Copy link

avielg commented Jun 6, 2024

Summary

We have a "clear cache" setting in our app, and when the user taps it we call apollo.store.clearCache(..) which succeeds, but the underlying sqlite file stays exactly the same size and is not removed. I tried to just delete the file after the success callback, but the store never re-creates it.
Is this a bug with clearCache function or am I doing something wrong?

Thank you!

Version

1.10.0

Steps to reproduce the behavior

Create a store like so:

let fileURL = try FileManager.default
  .url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  .appendingPathComponent("cache.sqlite")
let cache = try SQLiteNormalizedCache(fileURL: fileURL)
let store = ApolloStore(cache: cache)
self.client = ApolloClient(networkTransport: transport, store: store)

Try to clear cache:

self.client.store.clearCache { result in
  // result is success but the sqlite file is not deleted or any smaller
}

Logs

No response

Anything else?

No response

@avielg avielg added bug Generally incorrect behavior needs investigation labels Jun 6, 2024
@calvincestari
Copy link
Member

calvincestari commented Jun 6, 2024

Hi @avielg - I suspect the file size behaviour is due to the internals of sqlite; have you tried setting the shouldVacuumOnClear property in SQLiteNormalizedCache.init to true? By default it is false and when configured with true the vacuum command will be run whenever the sqlite cache is cleared. It seems that without forcing that behaviour sqlite is left to decide when to recover disk space which may not be immediately after deleting the records.

As for the file not being removed; we never remove the db file. It's created at startup if it doesn't exist but we have no code to delete the file.

@avielg
Copy link
Author

avielg commented Jun 6, 2024

oh shouldVacuumOnClear does it! Didn't know about this option, thank you!
This is good to close from my end :)

Copy link
Contributor

github-actions bot commented Jun 6, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response bug Generally incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants