balderdashy/sails — pull request #1407 by jonlong (2014-02-16 01:14:02+00:00)
Title: Fixing swig cache

In production, if `options.cache === true`, swig expects the value returned to be `'memory'`, otherwise an error is thrown.

## To test

Run `sails lift` using the swig templating engine and navigate to any page—the result should be a 500 error on the client and the following in the log:

```bash
error: Error rendering view at ::
error: Using layout located at ::
error: Server Error (500)
error: Error: Invalid cache option true found. Expected "memory" or { get: function (key) { ... }, set: function (key, value) { ... } }.
at validateOptions (/Users/jon/Projects/backchannel/node_modules/swig/lib/swig.js:94:15)
at parse (/Users/jon/Projects/backchannel/node_modules/swig/lib/swig.js:307:5)
at Object.precompile (/Users/jon/Projects/backchannel/node_modules/swig/lib/swig.js:455:23)
at Object.compile (/Users/jon/Projects/backchannel/node_modules/swig/lib/swig.js:560:16)
at Function.fns.swig.render (/Users/jon/Projects/backchannel/node_modules/sails/lib/configuration/consolidate.js:260:58)
at /Users/jon/Projects/backchannel/node_modules/sails/lib/configuration/consolidate.js:160:23
at /Users/jon/Projects/backchannel/node_modules/sails/lib/configuration/consolidate.js:113:7
at fs.js:266:14
at /Users/jon/Projects/backchannel/node_modules/sails/node_modules/glob/node_modules/graceful-fs/graceful-fs.js:90:5
at /usr/local/lib/node_modules/sails/node_modules/glob/node_modules/graceful-fs/graceful-fs.js:90:5
at Object.oncomplete (fs.js:107:15)
```

Swig will only throw this in production, so running `NODE_ENV=production sails lift` will get you there with a local copy.

## Source

The latest version of consolidate.js patches this:
https://github.com/visionmedia/consolidate.js/commit/e84860d55b2cb938c9a5525f83feba7f86dfeba7#diff-5c63ce9751803a854df2e222cea263e8

With the relevant line being this one:
https://github.com/visionmedia/consolidate.js/blob/master/lib/consolidate.js#L246