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

Cannot get caching & deep nesting working together #408

Closed
postmechanical opened this issue Feb 13, 2013 · 4 comments
Closed

Cannot get caching & deep nesting working together #408

postmechanical opened this issue Feb 13, 2013 · 4 comments

Comments

@postmechanical
Copy link

I'm having trouble getting caching with deep nesting. The cache is only invalidated when an attribute of the top level object changes not when an attribute of any nested object changes. I can reproduce the problem locally by enabling caching (cache_all_output and cache_sources both true) with a file store cache store.

top level view

object @GAMe
cache @GAMe
attributes :id, :name, :description, :active, :reminder_count, :created_at, :updated_at
child(:releases => :releases) {
extends "release/show"
}

second level view

object @Release
cache @Release
attributes :id, :active, :game_id, :lock_release_date, :created_at, :updated_at
child(:release_date => :release_date) {
extends "release_date/show"
}

third level view

object @release_date
cache @release_date
attributes :id, :date_range_end, :date_range_start, :up_votes, :down_votes, :evidence, :release_id, :string_representation, :user_id, :submitter_type, :active, :created_at, :updated_at

Any assistance would be greatly appreciated.

@databyte
Copy link
Collaborator

The lower level items have to touch the update_at timestamp of the upper level items. It's a typical Rails 3.x approach to fragment caching. In Rails 4.0, "russian doll caching" is introduced and we don't have support for that here. In other words, there's no automatic cache invalidation based on templates includes without working it into your models.

If you need help on the model setup, I can walk you through it. (basically it's a touch on save)

@postmechanical
Copy link
Author

Great to hear. Would love to see that covered in the documentation. Thanks.

@jharbert
Copy link

jharbert commented Nov 6, 2013

@databyte Are you stating that "Russian Doll" cache digest caching is not supported in RABL, or that cache invalidation is not inherently supported?

I'm running into an issue that seems to be the same one found here: #413

Removing the "cache @campaign" line below fixes the issue, but does not allow for cache digest style caching..

campaign_groups/show.rabl:

object @campaign_group
cache @campaign_group

attributes :id, :name

child(:campaigns) do
extends "campaigns/show"
end

campaigns/show.rabl:

object @campaign
cache @campaign

attributes :id, :name

Error:

TypeError - no _dump_data is defined for class Proc:
activesupport (4.0.0) lib/active_support/cache/file_store.rb:92:in block in write_entry' activesupport (4.0.0) lib/active_support/core_ext/file/atomic.rb:23:inatomic_write'
activesupport (4.0.0) lib/active_support/cache/file_store.rb:92:in write_entry' activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:135:inwrite_entry'
activesupport (4.0.0) lib/active_support/cache.rb:362:in block in write' activesupport (4.0.0) lib/active_support/cache.rb:519:ininstrument'
activesupport (4.0.0) lib/active_support/cache.rb:360:in write' activesupport (4.0.0) lib/active_support/cache.rb:560:insave_block_result_to_cache'
activesupport (4.0.0) lib/active_support/cache.rb:298:in fetch' rabl (0.9.0) lib/rabl/cache_engine.rb:18:infetch'
rabl (0.9.0) lib/rabl/helpers.rb:105:in fetch_result_from_cache' rabl (0.9.0) lib/rabl/engine.rb:283:incache_results'
rabl (0.9.0) lib/rabl/engine.rb:39:in render' rabl (0.9.0) lib/rabl/partials.rb:27:inobject_to_hash'
rabl (0.9.0) lib/rabl/partials.rb:14:in partial' rabl (0.9.0) lib/rabl/builder.rb:124:inextends'
rabl (0.9.0) lib/rabl/builder.rb:34:in block in compile_hash' rabl (0.9.0) lib/rabl/builder.rb:33:incompile_hash'
rabl (0.9.0) lib/rabl/builder.rb:21:in block in build' rabl (0.9.0) lib/rabl/builder.rb:166:incache_results'
rabl (0.9.0) lib/rabl/builder.rb:20:in build' rabl (0.9.0) lib/rabl/engine.rb:53:inblock in to_hash'
activerecord (4.0.0) lib/active_record/relation/delegation.rb:13:in map' rabl (0.9.0) lib/rabl/engine.rb:53:into_hash'
rabl (0.9.0) lib/rabl/engine.rb:39:in block in render' rabl (0.9.0) lib/rabl/engine.rb:285:incache_results'
rabl (0.9.0) lib/rabl/engine.rb:39:in render' rabl (0.9.0) lib/rabl/partials.rb:27:inobject_to_hash'
rabl (0.9.0) lib/rabl/builder.rb:108:in child' rabl (0.9.0) lib/rabl/builder.rb:46:inblock in compile_hash'
rabl (0.9.0) lib/rabl/builder.rb:45:in compile_hash' rabl (0.9.0) lib/rabl/builder.rb:21:inblock in build'
rabl (0.9.0) lib/rabl/builder.rb:166:in cache_results' rabl (0.9.0) lib/rabl/builder.rb:20:inbuild'
rabl (0.9.0) lib/rabl/engine.rb:51:in to_hash' rabl (0.9.0) lib/rabl/engine.rb:63:into_json'
rabl (0.9.0) lib/rabl/engine.rb:39:in block in render' activesupport (4.0.0) lib/active_support/cache.rb:298:inblock in fetch'
activesupport (4.0.0) lib/active_support/cache.rb:558:in block in save_block_result_to_cache' activesupport (4.0.0) lib/active_support/cache.rb:519:ininstrument'
activesupport (4.0.0) lib/active_support/cache.rb:557:in save_block_result_to_cache' activesupport (4.0.0) lib/active_support/cache.rb:298:infetch'
rabl (0.9.0) lib/rabl/cache_engine.rb:18:in fetch' rabl (0.9.0) lib/rabl/helpers.rb:105:infetch_result_from_cache'
rabl (0.9.0) lib/rabl/engine.rb:283:in cache_results' rabl (0.9.0) lib/rabl/engine.rb:39:inrender'
app/views/api/v1/campaign_groups/show.rabl:2:in `_app_views_api_v__campaign_groups_show_rabl___3505930832068356729_70246717977080'

@jharbert
Copy link

jharbert commented Nov 6, 2013

BTW:

I've traced my issue to the following inside of the Campaign model:

campaign.rb

after_initialize :set_overrides

  def set_overrides
    Offer::OVERRIDEABLE.each do |method_sym|
      offer.send(method_sym)
    end
  end

It appears that the 'send' is causing the issue. If I change it to 'read_attribute', it caches correctly. I still am unsure if RABL is caching correctly to support the russian doll style caching, but at least I've narrowed down the 'no dump_data' Proc issue

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

No branches or pull requests

3 participants