27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2. Very quick check for<br />

/public/projects/1.html<br />

3. Not found...<br />

Go to the application!<br />

4. Application routes<br />

request to controller<br />

Page and action caching<br />

In development mode, caching is turned off by default. Obviously, in development<br />

mode you don’t care so much about caching, as all requests are going to be local and<br />

not on a heavy-load server. You can turn caching on by going into config/environments/<br />

development.rb and changing this line<br />

config.action_controller.perform_caching = false<br />

to this:<br />

1. Request comes in for<br />

GET /projects/1<br />

Browser<br />

Web Server<br />

/public/projects/1.html<br />

Application<br />

config.action_controller.perform_caching = true<br />

Without this option, you can still have caches_page in your controllers, it just won’t<br />

do anything. With it turned on, your pages will be cached upon their first request.<br />

Launch rails server again and this time go to http://localhost:3000/projects/1.<br />

In the server output, you’ll see an additional line:<br />

Write page /.../ticketee/public/projects/1.html (0.3ms)<br />

2. Very quick check for<br />

/public/projects/1.html<br />

1. Request comes in for<br />

GET/projects/1<br />

Controller<br />

Browser<br />

Web Server<br />

/public/projects/1.html<br />

6. Request sent back to browser<br />

5. Controller creates<br />

/public/projects/1.html<br />

4. Page sent back to browser<br />

449<br />

Figure 16.4 First request, no cached page<br />

3. Found! It's dangerous<br />

to go alone, take this<br />

Figure 16.5 Subsequent<br />

requests, cached page

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!