rails-api/active_model_serializers — pull request #693 by joaomdmoura (2014-10-23 17:33:34+00:00)
Title: Cache Support at AMS 0.10.0

This is a implementation of cache support to the new version of AMS.

It started originally at the mailing list:
[AMS: Caching](https://groups.google.com/forum/#!topic/rails-api-core/FRy7GMbGEMI) with *Matthijs Langenberg*.
[New Cache Support on AMS](https://groups.google.com/forum/#!topic/rails-api-core/kxP0WxWzFEg). with me

This implementation proposes x different approaches of the old versions of AMS.

- A different syntax. (no longer need the cache_key method)
- An options argument that have the same arguments of ```ActiveSupport::Cache::Store```, plus a ```key``` option that will be the prefix of the object cache on a pattern ```"#{key}-#{object.id}"```.
- It cache the objects individually and not the whole Serializer return, re-using it in different requests (as a show and a index method for example.)

There are many benefits on this approach:

- You can easily know which will be your final cache key, so you can expire it with any custom code.
- You can use all options of ```ActiveSupport::Cache::Store``` (:expires_in for example)
- All objects will be cached individually and re-used on any other return needed
- It keeps you Serializer clean by not depending on old ```cache_key``` method.