我读了rabl caching doc而且我不知道如何缓存代码片段。 我有这样的 View (还有更多代码,但为了简单起见,我删除了它):
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)
最佳答案
正在关注 this线程,我将 :event child 移动到部分并缓存这个部分。
显示.rabl.json:
object @video
attributes :id, :user_id, :event_id
child :event do
extends "event"
end
child :user do
attributes :id
end
事件.rabl.json:
object @event
cache @event, :expires_in => 2.hour
attributes :id
node(:name) { |event| event.name }
它对我很有用。
关于ruby-on-rails - rabl View 中的片段缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13192550/