saoudrizwan / Disk

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

Expiry options for objects #15

Closed smarkars closed 6 years ago

smarkars commented 6 years ago

Hi I'm using this library in my application and it's wonderful.

Just wondering can we have expiry setting for objects that are added to cache.

Thanks.

saoudrizwan commented 6 years ago

Hey @skartys thanks for the kind words!

I've thought about implementing this, but ultimately felt like it goes a bit out of Disk's scope.

Let's say we have a struct called Document and we give this struct a Date variable called expirationDate.

struct Document {
    let title: String
    let expirationDate: Date
}

So the way expiry would work on iOS would require us to basically (1) iterate through all our Documents and (2) find those whose 'expirationDate' date value is before today, and then (3) delete those Documents. All this could be done, for example, when the application launches (so in didFinishLaunching in your App Delegate.)

This kind of practice is best accomplished tailored to your own specific needs, i.e. you could create a folder called DocumentsThatWillExpire and simply follow ^ steps to manage your expired files. This ensures good performance, as iterating through the entire file system would be thread intensive.