# Caching suggestions

**URL:** <https://www.ruby-forum.com/t/caching-suggestions/52807>\
**Category:** Rails\
**Created:** [January 19, 2006, 8:56am UTC](https://www.ruby-forum.com/t/caching-suggestions/52807 "2006-01-19T08:56:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 19, 2006, 8:56am UTC](https://www.ruby-forum.com/t/caching-suggestions/52807/1 "2006-01-19T08:56:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vivek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/77aa72/32.png) [@vivek](https://www.ruby-forum.com/u/vivek)\
**Post date:** [January 19, 2006, 9:05am UTC](https://www.ruby-forum.com/t/caching-suggestions/52807/2 "2006-01-19T09:05:47Z")

</div>

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: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Vivek K.  
Sent: Wednesday, January 18, 2006 11:18 PM  
To: removed\_email\_address@domain.invalid  
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
