Allow writing a container multiple times.

We still only format/build the result once, but we now cache the result
and re-use it on subsequent calls to #write.

Closes #155.