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

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: [email protected]
[mailto:[email protected]] On Behalf Of Vivek K.
Sent: Wednesday, January 18, 2006 11:18 PM
To: [email protected]
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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs