【问题标题】:Fragment caching in a rabl view?rabl视图中的片段缓存?
【发布时间】:2012-10-22 22:53:33
【问题描述】:

我阅读了rabl caching doc,但我不知道如何缓存代码片段。 我有这样的观点(有更多代码,但为了简单起见,我将其删除):

object @video

attributes :id, :user_id, :event_id

child :event do
  attributes :id
  node(:name) { |event| event.name }
end

child :user do
  attributes :id
end

我想缓存 :event child 两个小时。我该怎么做?

我正在使用 rabl(0.7.6)、rails(3.2.0)、ruby(1.9.3p125)

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 caching rabl


    【解决方案1】:

    this 线程之后,我将 :event child 移动到部分并缓存此部分。

    show.rabl.json:

    object @video
    
    attributes :id, :user_id, :event_id
    
    child :event do
      extends "event"
    end
    
    child :user do
      attributes :id
    end
    

    event.rabl.json:

    object @event
    cache @event, :expires_in => 2.hour
    
    attributes :id
    node(:name) { |event| event.name }
    

    它对我很有用。

    【讨论】:

      猜你喜欢
      • 2012-01-13
      • 2012-07-02
      • 2014-12-23
      • 2016-07-18
      • 2011-11-23
      • 2010-10-19
      • 1970-01-01
      • 2014-07-04
      • 2019-12-23
      相关资源
      最近更新 更多