racker/gutsy — pull request #63 by kans (2012-03-20 23:00:47+00:00)
Title: Cache api calls

This branch started out simple and unfortunately moved to touch many things.

Among other things, we now have a create_caching_middleware function (almost a decorator really) in Utils that takes a name, ttl and a function pointer to the middleware. It defines a new interface for middlewares which take the familiar (req, res, next) and the new (payload, api_config). payload is a simple object with data and errors which is what all middlewares set anyway. Middlewares just update the payload and the rest is handled for them (including caching).

Also, tests for middlewares being existent was moved to create_caching_middleware instead of making each middleware check.

Finally, api_config is a pointer to req.devops[name]. This is passed because the system is over defined otherwise and tracking down new_relic vs. newrelic took me an hour or so. The middlewares probably shouldn't know such a thing as req.devops exists anyway- they only should care about their settings.

Otherwise, I got so frustrated with inconsistent names that I changed all newrelics to new_relic, etc, everywhere. I would be fine with the opposite convention. Before working on the tests, I merged in the mock_with_nock branch to make the future merge easier I hope. Some extra cleanup can be done their to get rid of the module/middleware name mappers which are no longer needed.