jsonapi-renderer
jsonapi-renderer copied to clipboard
Unify Simple and Cached resource output – both returns array of hash objects
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
.
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.