Is every relavant calculation performed every time the page is loaded?

痴心易碎 提交于 2019-11-29 17:34:21

In addition to the resources that @Kelseydh provided, you can also consider memoization for when you hit the same function multiple times as part of the same request. However, it will not retain its value after the request is processed.

Yes it will be recalculated every time. If this is an expensive operation you should add a counter_cache (guide: http://railscasts.com/episodes/23-counter-cache-column) for the count and look into caching the query result using a service like memcache.

Many caching strategies exist, but for the database/Rails app itself Russian doll caching is considered the most flexible approach. If your data doesn't update often (meaning you don't need to worry about cache expiration often) you may be able to get way with page caching -- if so, count yourself lucky.

Some resources to get you started:

DHH on Russian Doll Caching: https://signalvnoise.com/posts/3113-how-key-based-cache-expiration-works).

Railscast on cache keys: http://railscasts.com/episodes/387-cache-digests

Advanced caching guide: http://hawkins.io/2012/07/advanced_caching_revised/

Not free, but I found this series was what really let me understand various forms of caching correctly: http://www.pluralsight.com/courses/rails-4-1-performance-fundamentals

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!