stackmob/newman — pull request #25 by arschles (2013-04-11 03:02:56+00:00)
Title: CachingJSONR

This PR introduces a `JSONR[T]` container that is meant to be long lived (like its contained `JSONR`), and caches the `Result[T]` for each `JValue` that it is passed.

* `HttpResponse` and the applicable DSL, specs, etc have all been updated to use `CachingJSONR[T]`
* To get benefit from caching, a client must ensure that the existing `JSONR[T]` whose parsed results should be cached is long lived in memory (ie: in a `val`)
* This change will be breaking. There's a class wrapper included in `com.stackmob.newman.jsonscalaz` that adds the `cached` method to any `JSONR[T]`, which provides the migration path. See below for example usage

Recommended usage of `CachingJSONR[T]`:

```scala
import com.stackmob.newman.jsonscalaz._

implicit val myJSONR = new JSONR[Int] {
override def read(json: JValue): Result[Int] = json match {
case JInt(i) => i.successNel[Error]
case other => UnexpectedJSONError(...).failNel[int]
}
}.cached

val myResponse: HttpResponse = ...
val responseBodyInt: Result[Int] = myResponse.bodyAs[Int]
```

The difference between the above code and equivalent existing code is the `.cached` call at the end of the `JSONR[Int]` definition