-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implement Russia Doll Cache #1045
Comments
Hey @joaomdmoura ! Thanks for all your work. class FullMarkerSerializer < MarkerSerializer
attributes :name, :special_offer
belongs_to :category
cache key: 'business_full_markers', only: [:name, :special_offer, :category]
cache key: 'business_markers', except: [:name, :special_offer, :category]
def special_offer
object.sale.special_offer.try(:description)
end
end I'm correct that now it doesn't work? |
No, @mib32 the Russian Doll cache is a technique of nesting fragment caches to maximize cache hits. By nesting fragment caches, it ensures that caches can be reused even when content changes. I'll need to check but what you posted might work now, not because of the inheritance, but because the cache is based on the model, and not on the serializer, anyway, I'm not so sure,I've to double check. |
@joaomdmoura I'm trying to use this technic to improve the response time and the only way that I thought was caching the Right know I have something like this: class ActiveModel::Serializer::Adapter::FlattenJsonWithCustomCache < ActiveModel::Serializer::Adapter::FlattenJson
def as_json(options = nil)
tags = serializer.try(:cache_tags)
# This `cache_key` was overwritten
Rails.cache.fetch(serializer.cache_key, tag: tags) do
super
end
end
end # initializers/ams.rb
ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::FlattenJsonWithCustomCache ps: I added I hope that it helps with something and if someone has ideas to improve this workaround I will be very happy! =D |
@joaomdmoura I had to change the cache to the |
ref: #1372 |
tl;dr
Implementing a Russia Doll Cache that will enable us to increase our performance.
fetch-multi
is an awesome plusWe have already implemented cache and fragment cache on 0.10.x, but we still need to make it better by implementing a Russia Doll Cache that will enable us to increase our performance when serializer different set of a resource.
related to issues:
related to PRs:
The text was updated successfully, but these errors were encountered: