# Automatically fill the page cache

**URL:** <https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254>\
**Category:** Rails\
**Created:** [November 14, 2008, 12:32am UTC](https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254 "2008-11-14T00:32:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [November 14, 2008, 12:32am UTC](https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254/1 "2008-11-14T00:32:12Z")

</div>

Hi,

I have my whole site cached with page cache, because each page needs  
some time to render. What I would like to do is to delete all files in  
the cache (I have no problem with that). But after I have deleted  
everything, I would like to cache each and every file again, so that my  
visitors don’t experience any long load times. Any ideas on how to do  
this the most efficiently. It’s a cache of more than 5.000 pages. Any  
ideas are welcome. Thanks.

Kind regards,

Nick

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [November 14, 2008, 3:19am UTC](https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254/2 "2008-11-14T03:19:04Z")

</div>

Hi Nick,

Nick S. wrote:

> …after I have deleted everything, I would like to cache each  
> and every file again, so that my visitors don’t experience any  
> long load times. Any ideas on how to do this the most efficiently.

As far as I know, the only way to get a page into the cache is to pull  
it  
there with a request from a client. OTOH, the client need _not_ be a  
browser. You could write a script that ‘computes’ all the possible  
requests  
(reflecting on controller methods) and then issues them (to the server  
through the cache) using Ruby’s net/http library. It’s not elegant, and  
there’re likely to be views that wouldn’t get rendered without making  
your  
script smarter, but it might not be a bad first step.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [November 14, 2008, 12:39pm UTC](https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254/3 "2008-11-14T12:39:02Z")

</div>

Well, the web server (eg apache) wouldn’t have that much load, would  
it? I bet 99% of the load will be in your app anyways.

In terms of traffic I would recommend a locally installed wget or curl  
client just pulling everything. And in terms of cpu load: you could  
run that script reniced(see “man nice”) level, so it doesn’t block  
incoming requests.

This way your users might have to wait a bit while the page cache  
slowly grows, and then you are back at hi speed.

Or else: create an identical instance on a second machine, have the  
cache recreated there, copy everything off that machine onto your live  
system.

/eno

====================================================================  
A wee piece of ruby every monday: [http://1rad.wordpress.com/](http://1rad.wordpress.com/)

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [November 14, 2008, 9:36am UTC](https://www.ruby-forum.com/t/automatically-fill-the-page-cache/153254/4 "2008-11-14T09:36:53Z")

</div>

Hi Bill,

thanks for the reply. I already tought of this solution, but this would  
mean hammering my own server for a while. Isn’t there a more elegant  
way, so that the web server is not involved but that Rails handles the  
cache generation.

Kind regards,

Nick
