saoudrizwan / Disk

Easily persist structs, images, and data on iOS
MIT License
3.1k stars 171 forks source link

Caches is erased too soon #44

Closed j0cker closed 6 years ago

j0cker commented 6 years ago

Hi!.

This is not really an issue it is more a doubt, Please help.

Im using the following code to save a codable class:

try! Disk.save(self.order, to: .caches, as: Constants.PEDIDO_FOLDER)

Where self.order is the codable class and Constants.PEDIDO_FOLDER is "VASH/Pedido.json"

And when a want to have the memory of the codable class i do it this way:

self.pedido = try Disk.retrieve(Constants.PEDIDO_FOLDER, from: .caches, as: Order.self)

This is working perfectly!. But if i leave the app like 30 minutes inactived and then i reopen the app. The caches memory is not longer there. My doubt is if there is a way to have the memory for a longer time in caches.

Thanks a lot!.

saoudrizwan commented 6 years ago

Hey there! The Caches directory is managed by iOS internally, so it may clear up if your phone is running low in storage space. You usually only want to use this directory for data you can easily retrieve again if the user demands it. If you want to store something with more control over its life time, you should use the Application Support directory, or create your own custom directory that you can manage with custom expiration dates. For example, every time the user opens your app, check each file and it's creation date, compare it to its set expiration date, and delete that file if it's lived past its expiration date.

j0cker commented 6 years ago

Thanks a lot, i will try with .applicationSupport