Cache nameFactory changes in TaskTree

When walking changes, it is likely that many changes will get requeried
since many of the changes queried will also be in the output. Cache the
output of these mostly small (and thus not very memory intensive)
queries to avoid repeating them.

In a sample walking ancestors use case this caching for over 33K
ChangeNodes results in about 1/3 of the original queries, and saves a
small but measurable amount of the total time. In the case of a
task.config which walks all dependencies for a change when run with
status:open --no-limit --task--applicable the gain can be seen below.

Before this change: 4m47s 4m56s 4m22s 5m5s 4m27s
After this change:  4m18s 4m4s 4m37s 3m56s 4m5s

Change-Id: Ibe04c5fae8807635be378d6627dbdc7d8bd724b9
2 files changed