我读了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
我想缓存:活动孩子两个小时。我怎么能这样做?
我正在使用rabl(0.7.6),rails(3.2.0),ruby(1.9.3p125)
答案 0 :(得分:5)
在this线程之后,我将:event子事件移动到部分并缓存此部分。
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 }
这对我有用。