# Just how the hell do you set Cache-Control max-age?

**URL:** <https://www.ruby-forum.com/t/just-how-the-hell-do-you-set-cache-control-max-age/163636>\
**Category:** Rails\
**Created:** [March 23, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/just-how-the-hell-do-you-set-cache-control-max-age/163636 "2009-03-23T13:49:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [March 23, 2009, 1:49pm UTC](https://www.ruby-forum.com/t/just-how-the-hell-do-you-set-cache-control-max-age/163636/1 "2009-03-23T13:49:44Z")

</div>

Hi all,

Ive been googling for couple of hours and I just cant figure it out. I  
want to set the max-age value to 300 for the WHOLE application,  
regardless of development or production mode.

Is there anyone that knows?

Petr

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [March 23, 2009, 5:31pm UTC](https://www.ruby-forum.com/t/just-how-the-hell-do-you-set-cache-control-max-age/163636/2 "2009-03-23T17:31:56Z")

</div>

I would probably set this in the web front-end (apache, etc) This is  
where I do expires stuff. I have to be careful though since most of  
the examples I’ve seen literally say to set it globally, but Rails  
uses the public directory for caching as well.

For max age, I’d consider having Apache set it, so it will also be set  
for cached files, if you use any caching.

–Michael

On Mon, Mar 23, 2009 at 7:49 AM, Petr J.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
(Ruby, Rails, Random) blog: [http://skandragon.blogspot.com/](http://skandragon.blogspot.com/)

---

<div class="post-metadata">

**Author:** ![petrjanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee7513/32.png) [@petrjanda](https://www.ruby-forum.com/u/petrjanda)\
**Post date:** [March 25, 2009, 3:35pm UTC](https://www.ruby-forum.com/t/just-how-the-hell-do-you-set-cache-control-max-age/163636/3 "2009-03-25T15:35:05Z")

</div>

Hi Petr,

Rails provides ActionController#expires\_in and  
ActionController#expires\_now  
for doing this on a case-by-case basis, but Michael is right that this  
is  
something you want to be doing on your HTTP server, not in your  
application.
