Shopify/identity_cache — pull request #122 by arthurnn (2014-02-19 17:31:39+00:00)
Title: Only create CollectionProxy when need it.

### Problem
Rails 4, has a big performance hit on the `reader` method. `reader` instantiate a `CollectionProxy` and return it. On rails 4 they preload the scopes when creating the `CollectionProxy`.

### Solution
When we un-marshal the object, we dont need to create the `CollectionProxy` right away, as it might not even be used. This is deferring the `.reader` call to when we call `fetch_#{association_name}`.

This is the example file I used to benchmark the change https://gist.github.com/arthurnn/9096869.
Numbers:
Rails 3:
```
user system total real
20.220000 2.040000 22.260000 ( 23.073374)
```
Rails4:
before:
```
user system total real
36.310000 2.480000 38.790000 ( 39.942972)
```

after:
```
user system total real
21.880000 2.200000 24.080000 ( 24.851130)
```