visionmedia/consolidate.js — pull request #38 by cstigler (2012-07-05 10:02:19+00:00)
Title: Dust.js Template-function Caching

At the beginning of the consolidate.js file, a comment states "On top of this, when an engine compiles to a 'Function', these functions should either be cached within consolidate.js or the engine itself via 'options.cache'."

So this template-function caching is a stated goal of Consolidate, but as far as I can tell it hasn't been implemented. Well, at least for Dust.js it definitely hasn't. Dust has no internal caching, and Consolidate provides no template-function caching, so the templates are recompiled on each call (the renderSource() method currently used calls compileFn() internally in Dust.js).

This commit provides 1) a quick fix for the cache to store both functions and strings without mixing them up, and 2) template-function caching for Dust.js.

I implemented the template-function caching outside of the read() method to keep that from causing problems with backwards-compatibility, and also left the string caching intact to handle edge cases like a cache access before the function compile/cache finishes.

Let me know if there's anything I need to fix.