Its pretty good to use active-record in ruby on rails, relationships, find_by methods, where queries everything makes your life much more simpler as a developer but sooner or later your application becomes slow. At that time you need to work on optimizations. There are lot of work around for optimizations and one of them in caching the queries. The company I work for is StudyPad and we have a product ie splashmath and that has over 9 millions users using it across multiple platforms. The amount of traffic that we get is pretty huge and caching one of the thing that helped us to solve out scaling problems. Here is quick idea to cache your queries in memcache.
There are few requirements for this. First is the dalli gem and memcache installed on your machine.
Basic structure of the application.
We have lot of static/seed data which change very less and the queries on those things are pretty high. So first thing to handle that static data.
1 2 3 4 5 6 7
So in order to get skills for a grade, its pretty simple
Now for that matter every time we are fetching skills for a grade its gonna hit the database and get the results. So its time to get this query and its results cached.
Assuming you have configured dalli gem easily and you have memcached up and running. Here is a simple method to cache the results
1 2 3 4 5
So instead of fetching skills like
we are gonna get it like