pinterest / PINCache

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow enumeration of PINCache

vade opened this issue · comments

Hello

Firstly, thank you for PINCache, its been a breeze to set up and work with, so much appreciated!

I'm wondering why the enumerateObjectsWithBlock and fam isn't part of the PinCaching protocol - it might be nice to be able to enumerate all objects in your cache(s) (without loading flushed to disk objects into ram unless you specifically request to do so).

I get there's likely nuances im not thinking of, but being able to enumerate your entire cache is a use case that's very helpful on my end as unintuitive as it is.

Obviously you can do that now with the memory and disk caches manually, but you run into cases the same object may be backed by both caches (hot and on disk).

I imagine there's nuances to equality checking (ensuring the hashes for the disk cache object and memcache objects match esp if a new object has to be deserialized to check for equality - could be slow).

Its early and I'm likely missing some subtle details - any chance for a global enumerateObjectsWithBlock which fast paths in ram and only loads the disk items that aren't hot? Could be nicer than having folks roll their own.

Much appreciated and thanks again.

The history behind it not being in the PINCaching protocol is there was no clean way to keep the existing API. All the other methods matched one to one in disk and memory cache but the enumeration blocks for disk and memory are different. When we added the protocol we wanted to keep the existing API.

As far as adding a enumerateObjectsWithBlock method on PINCache, I don't see a particular problem with creating one (pull requests welcome!). It would likely require a new method on PINDiskCache which just enumerated _metadata and provided its keys.

Sorry, didn't mean to close, will keep open as an enhancement request.

Cool. I may give that a go myself!