Minor optimisations in caching code.