hakunin
hakunin

Reputation: 4231

Rails: cache with substitutes?

I have a partial I am caching, but one part of it is dynamic:

- cache @product do
  .product
    #.....
    .price = format_money(@product.money)

And would like to turn it into something like this:

- cache_subst @product, {price: format_money(@product.money)} do
  .product
    #.....
    .price {{price}}

Is there some gem or method that does this?

Update:

Please don't suggest making money part of the key in any way, thats what we're doing right now.

Upvotes: 0

Views: 45

Answers (1)

Uri Agassi
Uri Agassi

Reputation: 37419

Since the variability of the cached view is the currency, and there is a limited number of currencies, I think the best strategy would be to add the currency to the cache key:

- cache [@product, format_money(@product.money)] do
  .product
    #....
    .price = format_money(@product.money)

Upvotes: 0

Related Questions