Improve caching of namespaces.

Change-Id: I4799f0941fa7e356e43e681b05969744e5f14f57