Replace global cache with local in cache()

Since we are using the function as an object, it makes sense to employ a
local Ordered Dict of the correct size inside