Adding cache support to version 0.10.0

It's a new implementation of cache based on ActiveSupport::Cache.
The implementation abstracts the cache in Adapter class on a
private method called cached_object, this method is intended
to be used on Adapters inside serializable_hash method in order
to cache each instance of the object that will be returned by
the serializer.

Some of its features are:
- 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.)
This commit is contained in:
Joao Moura
2014-10-20 21:38:20 -02:00
committed by João Moura
parent 42644544e1
commit 8a432ad2b3
17 changed files with 265 additions and 22 deletions

View File

@@ -28,6 +28,7 @@ module ActiveModel
@serializer = CommentSerializer.new(@comment)
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)
ActionController::Base.cache_store.clear
end
def test_includes_post_id

View File

@@ -21,6 +21,7 @@ module ActiveModel
@serializer = ArraySerializer.new([@first_post, @second_post])
@adapter = ActiveModel::Serializer::Adapter::JsonApi.new(@serializer)
ActionController::Base.cache_store.clear
end
def test_include_multiple_posts

View File

@@ -6,6 +6,7 @@ module ActiveModel
class JsonApi
class HasManyTest < Minitest::Test
def setup
ActionController::Base.cache_store.clear
@author = Author.new(id: 1, name: 'Steve K.')
@author.posts = []
@author.bio = nil