Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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