3

I read rabl caching doc and I don't get how I can cache fragment of code. I have a view like this (there more code, but I removed it for simplicity's sake):

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

And I want to cache :event child for two hours. How can I do that?

I'm using rabl(0.7.6), rails(3.2.0), ruby(1.9.3p125)

Nat Ritmeyer
  • 5,634
  • 8
  • 45
  • 58
mr.The
  • 445
  • 5
  • 17

1 Answers1

5

Following this thread, i move :event child to partial and cache this partial.

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 }

And it work good for me.

mr.The
  • 445
  • 5
  • 17