Closed nsmith- closed 4 years ago
I had a question about one line, but this looks right. Give me a checkmark or thumbs up or something and I'll merge it.
My one other complaint is there's a lot of key in cache
checks that may be optional if we trust the virtual array to have correct type before materialization. This isn't a huge deal, but there may be unnecessary overhead in the cases where the cache is backed by something slow.
You're right. In fact, if we trust try ... catch KeyError
logic, then the cache
doesn't have to have a __contains__
operation defined, and it can be more thread-safe because of the time that elapses between the key check and the extraction.
In python's Mapping
abc, __contains__
is not abstract because of this very logic.
Also require cache to conform to MutableMapping interface, i.e. KeyError is the only exception that indicates trouble.