Ensure the type map's cache is thread safe

Thanks to @thedarkone for pointing out that an instance of this object
is used in a shared context.