spotify / SPTPersistentCache

Everyone tries to implement a cache at some point in their iOS app’s lifecycle, and this is ours.
Apache License 2.0
1.24k stars 77 forks source link

Need help about caching #99

Open CavalcanteLeo opened 6 years ago

CavalcanteLeo commented 6 years ago

I have an app, that is a comic book reader, so the user can download a book then read it later, even without internet.

I'm thinking to cache all pages(images) of the book with SPTPersistentCache. I need to save each book in a different folder, ex: spider man will be saved on a folder spider-man/pages, minions will be saved on minions/pages and so on...

Also SPTPersistentCache can't garbage the books downloaded, it must keep the cache until the user delete that specific book. Also no disk size limite.

What I need is the very same way Spotify does with offline musics downloaded. Can I do that?

chrisbtreats commented 6 years ago

I don't know about the file paths but you can prevent garbage collection on cached items by "locking" them using the lockDataForKeys:callback:onQueue

CavalcanteLeo commented 6 years ago

Thanks @chrisbtreats lockDataForKeys:callback:onQueue works perfect for what I need

The idea behind the folder is to show the user how much storage to book is taking. Each book can have several pages, each page is an image. So, i need to calculate something like this:

book_1: 115MB
book_2: 333.3MB
book_3: 514.3MB

If there is another way to calculate the size of an array of keys, I won't need to change the folder

totalUsedSizeInBytes shows the entry cache, not for a couple of keys related to a specific book

But if I can't do that, it will be so easy to calculate a size of a specific folder

CavalcanteLeo commented 6 years ago

I just read all the code, and it's not possible, but looks like it's possible to change the folder for each instance.

Also i will create that feature and submit a PR, something like: totalUsedSizeInBytesForKeys:callback