Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do a fragment caching in a rabl view?

I'm trying to do something like this:

cache "api/v1/cars_index/#{I18n.locale}/car/#{car.cache_key}" do
  attributes :id, :brand, :model_name, :fuel, :km, :year, :price
  node(:color) { |car| car.color.present? ? car.color : '' }
end
like image 589
Niels Kristian Avatar asked Dec 05 '11 10:12

Niels Kristian


People also ask

What is fragment caching?

Fragment caching does not actually cache a Web Form's code fragments directly; fragment caching refers to the caching of individual user controls (. ascx) within a Web Form. Each user control can have independent cache durations and implementations of how the caching behavior is to be applied.

What is fragment cache Rails?

Fragment Caching allows a fragment of view logic to be wrapped in a cache block and served out of the cache store when the next request comes in. For example, if you wanted to cache each product on a page, you could use this code: <% @products.


1 Answers

For those people who finds this question through a search or google.

Niels started an issue on Github which can be found here.

A developer created a great solution for this which has been merged into rabl since v0.6.2.

like image 117
Lisinge Avatar answered Nov 02 '22 14:11

Lisinge