# Caching column names

**URL:** <https://www.ruby-forum.com/t/caching-column-names/49813>\
**Category:** Rails\
**Created:** [December 8, 2005, 10:10pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813 "2005-12-08T22:10:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 8, 2005, 10:10pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813/1 "2005-12-08T22:10:55Z")

</div>

is there a setting/option to ActiveRecord::Base which will cache the  
columns  
after the first query - rather than querying the database for them each  
time?

## -a

# =============================================================================== | ara [dot] t [dot] howard [at] noaa [dot] gov | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | – bodhicaryavatara

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 8, 2005, 10:19pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813/2 "2005-12-08T22:19:04Z")

</div>

Ara.T.Howard wrote:

> is there a setting/option to ActiveRecord::Base which will cache the  
> columns after the first query - rather than querying the database  
> for them each time?

Sounds like you’re running under Development, not Production…

-Brian

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 8, 2005, 10:31pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813/3 "2005-12-08T22:31:16Z")

</div>

Ara.T.Howard wrote:

> is there a setting/option to ActiveRecord::Base which will cache the  
> columns  
> after the first query - rather than querying the database for them each  
> time?

Yes there is, altough you probably dont want to set it explicitly. Just  
switch to production enviroment and thats it!

Zsombor

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 8, 2005, 11:16pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813/4 "2005-12-08T23:16:26Z")

</div>

On Dec 8, 2005, at 1:18 PM, Brian V. Hughes wrote:

> Ara.T.Howard wrote:
> 
> > is there a setting/option to ActiveRecord::Base which will cache the  
> > columns after the first query - rather than querying the database  
> > for them each time?
> 
> Sounds like you’re running under Development, not Production…
> 
> -Brian

No I think Ara is asking about the sql queries being cached so the  
next time a .find is called and the object hasn’t changed it will be  
served from a cache without hitting the db? And he’s not talking  
about page or fragment caching that you can use in production mode.  
As far as I know there is nothing in AR yet that caches db queries  
but this would be a great addition to keep the level of db activity  
from being so chatty. Some certain ways of using AR can result in  
tons of queries to the db for each page render and it would be great  
if some of these were cached.

```
The question is how to implement this feature?

```

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [December 8, 2005, 11:40pm UTC](https://www.ruby-forum.com/t/caching-column-names/49813/5 "2005-12-08T23:40:51Z")

</div>

On Dec 8, 2005, at 2:08 PM, Ezra Z. wrote:

> > -Brian  
> > great if some of these were cached.
> 
> The question is how to implement this feature?
> 
> Cheers-  
> -Ezra Z.

```
Actually I take all of that back ;-) On a second reading of his

```

question, you guys were right that this is a difference between dev  
and production mode. In dev mode the columns are queried every time  
because in dev mode you can add a column to your table and rails will  
pick it up on the next request. In production mode these are cached  
and not issued every time. So yes switching to production mode will  
cahce the column name queries in AR.

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster  
[http://yakimaherald.com](http://yakimaherald.com)  
509-577-7732  
removed\_email\_address@domain.invalid
