jsonapi-renderer icon indicating copy to clipboard operation
jsonapi-renderer copied to clipboard

Unify Simple and Cached resource output – both returns array of hash objects

Open ViliusLuneckas opened this issue 6 years ago • 1 comments

This change unifies the output type of SimpleResourcesProcessor and CachedResourcesProcessor.

Before:

# No caching
result = JSONAPI::Serializable::Renderer.new(cache: false).render(collection)
result[:data].first.class # => Hash

# With caching
result = JSONAPI::Serializable::Renderer.new(cache: Rails.cache).render(collection)
result[:data].first.class # => String

# Parsing needed if you want to personalize result
result[:data] = json[:data].map { |json_string| JSON.parse(json_string) }

After:

# No caching
result = JSONAPI::Serializable::Renderer.new(cache: false).render(collection)
result[:data].first.class # => Hash

# With caching
result = JSONAPI::Serializable::Renderer.new(cache: Rails.cache).render(collection)
result[:data].first.class # => Hash

That's very important if you need to amend/personalize output of the JSONAPI::Serializable::Renderer.

ViliusLuneckas avatar Feb 24 '19 09:02 ViliusLuneckas

The kind of caching implemented here is not attributes caching but fragment caching, as the main bottleneck usually is generating the actual json. Attributes caching is quite easy to implement and could be a distinct feature.

beauby avatar Mar 07 '19 17:03 beauby