Skip to content

Conversation

ViliusLuneckas
Copy link

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.

@beauby
Copy link
Member

beauby commented Mar 7, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants