Refactored caching code.

Instead of having a method copyTemplate, we will dynamically check
whether we are caching or not, and decide whether to call ourself
or $this->cachedTemplate. We do this with the __call() method.