views:

33

answers:

2

For my site, I have models Category and Product, with hundreds of categories, each having thousands of products. For the Category views, I'd like to do something like average price of all the products included. And for the product views, I'd like the average for that product's category to appear.

So, with thousands of these calculations having to be stored somewhere, where's the best place to do it? Creating a lookup table with values? Or does caching/memoizing a Category action that calculates the average work fine?

A: 

Well, you can certainly use standard rails application cache and keep it all in memory. Few thousands of numbers isn't too much.

Example from the tutorial:

Rails.cache.read("city")   # => nil
Rails.cache.write("city", "Duckburgh")
Rails.cache.read("city")   # => "Duckburgh"
Nikita Rybak
A: 

Have a look at Cache Money for this.

Andrew Vit