Forum: Ruby on Rails Caching suggestions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 Vivek Krishna (Guest)
on 2006-01-19 08:56
(Received via mailing list)
Hi ,
  I have created a simple app which allows user logins and when user
logs in
a home page is shown which is built using some queries to the DB. I
tried
caching which didnt work properly because for some reason rails kep
loading
the old cache..Anyway What I was wondering is caching only avoids the
render
process but IMHO the queries are the most consuming.

My code is something like

def index
@messages =find_all_messages
# other stuff which does db query and some biz logic to create arrays
which
are used in the view
render :action =>'index'
end


Even though the index can be cached the  code to create the user's
homepage
related variables are recalculated?How do I avoid that?
Has anyone faced such an issue? I am thinking if storing the results in
a
temporary table till the session is alive is a good idea.or may be check
if
cache exists to avoid doing calculations,but there doesnt exist any such
API.

Any suggestions?

Regards
Vivek
3f900b38ec3b2c45427c354722fa4ce3?d=identicon&s=25 Tom Fakes (tomfakes)
on 2006-01-19 09:05
(Received via mailing list)
Take a look at Action caching:



class FooController < ApplicationController

            caches_action :index



            def index

                        .

            end

end



Action caching uses the Fragment cache configuration and stores the HTML
output to the client on the first request.



Action caching is implemented as a Before filter.  Any Before filter
defined
before the caches_action call will still be executed, so you can do
things
like check to see if the user is allowed to access this page.







  _____

From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Vivek Krishna
Sent: Wednesday, January 18, 2006 11:18 PM
To: rails@lists.rubyonrails.org
Subject: [Rails] Caching suggestions



Hi ,
  I have created a simple app which allows user logins and when user
logs in
a home page is shown which is built using some queries to the DB. I
tried
caching which didnt work properly because for some reason rails kep
loading
the old cache..Anyway What I was wondering is caching only avoids the
render
process but IMHO the queries are the most consuming.

My code is something like

def index
@messages =find_all_messages
# other stuff which does db query and some biz logic to create arrays
which
are used in the view
render :action =>'index'
end


Even though the index can be cached the  code to create the user's
homepage
related variables are recalculated?How do I avoid that?
Has anyone faced such an issue? I am thinking if storing the results in
a
temporary table till the session is alive is a good idea.or may be check
if
cache exists to avoid doing calculations,but there doesnt exist any such
API.

Any suggestions?

Regards
Vivek
This topic is locked and can not be replied to.