pratski
pratski

Reputation: 1488

Does rails cache static pages and assets automatically?

I have been reading about caching and all the resources available out there, but I am just not sure if I need to use 3rd party add-ons like Memcachier in my app. Other than the front pages (Static Pages like Homepage, About, Contact Us, Terms, Privacy) all other pages require authentication and are all dynamically created. It's a small social networking app so the show page, index page, edit page are all dynamically created. The index action is constantly going to be updated.

I want to know if Rails will automatically cache my static pages and assets such as css, javascript, images? What kind of caching should I be using?

Upvotes: 0

Views: 1374

Answers (1)

Benjamin Bouchet
Benjamin Bouchet

Reputation: 13181

If what you call static page are HTML files located in your public folder, they are directly served by your web server (ex: Apache), and the request don't even go through Rails

If they are files located in your app/views controller, the request goes through Rails, and it could be a good idea to implement page or fragment caching. Know that you can cache just parts of the pages, this is called fragment caching, and it's useful for dynamic pages that have static parts.

Also, you can link a cache to a record, so first time the view related to this record is displayed, the cache is generated and used for the next requests. Then when you modify this record the cache is invalidated and the process start over.

You don't need cache for your assets, they are compiles and not interpreted by Rails anymore in your production environment.

There is so many things about caching, and you can do a lot of good to your application with it (or a lot of bad is used incorrectly) and I cannot cover it all, let me give you some pointers that will teach you a lot:

http://railscasts.com/episodes/387-cache-digests

http://railscasts.com/episodes/169-dynamic-page-caching

http://railscasts.com/episodes/93-action-caching

http://railscasts.com/episodes/90-fragment-caching

http://railscasts.com/episodes/89-page-caching

Upvotes: 4

Related Questions