lassebunk/dish — pull request #12 by apauly (2014-10-21 13:44:53+00:00)
Title: Cache converted values

Added some basic caching for converted values to prevent unnecessary object recreations.

**Benchmark:**

```ruby
class Author < Dish::Plate; end
class Product < Dish::Plate
coerce :updated_at, ->(value) { Time.parse(value) }
coerce :authors, Author
end

api_response = [
{
title: "Test Product",
updated_at: "2013-01-28 13:23:11",
authors: [
{ id: 1, name: "First Author" },
{ id: 2, name: "Second Author" }
]
}
]

products = api_response.to_dish(Product)
Benchmark.realtime{
50000.times{
products.first.updated_at
products.first.authors
}
}
```
```
Without cache: 2.64122 seconds
With cache: 0.993074 seconds
```