pinterest / PINCache

Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make disk size trim algorithm more efficient

Quartme opened this issue · comments

commented

I'm using a PINDiskCache to store roughly 1000 images when it reaches the disk cache limit specified.

After the cache reaches it's limit, it looks like nearly every call to -setObjectAsync:forKey:completion: to add an item to the cache triggers one -trimDiskToSizeByDate: call. This call sorts the _metadata array so the code ends up sorting this same array repeatedly.

We could mitigate the costs of this sorting by either throttling the trim to once every 60s (could be configurable), or by using a data structure like a priority queue. I could submit a Pull Request for configurable throttling of the trim if needed. thanks