Your SlideShare is downloading. ×
0
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Caching By Nyros Developer
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Caching By Nyros Developer

912

Published on

Caching By Nyros Developer

Caching By Nyros Developer

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
912
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1.
    • Caching
  • 2. What is Caching ?
    • Caching is a process of temporarily storing a data likely to be used again and again.
    • Its an art of taking a processed webpage or part of webpage, and storing in a temporary location. If the same webpage is requested by user, then we can serve the cached version.
    • Caching is a cheep way of speeding up slow applications by keeping the results of calculations.
  • 3. (Where & When) – Caching ?
    • While developing an web application, we need to take care of caching also.
    • When application goes live and more people are using the application, you are required to use caching.
    • Sometimes web application is slow, and you have heavy traffic and you want to run the site in slow hardware or shared host, then you need caching.
  • 4. Caching In ROR
    • Ruby on rails provides an build in frame work for caching.
    • Which helps to make use of the functionality with less code.
    • caching in RoR is very powerful standard feature.
  • 5. Caching Types
    • Page caching
    • Action caching
    • Fragment caching
  • 6. Page Caching
    • Page Caching is an approach to caching where entire action output is stored in HTML file, That the webserver can serve without going through Action pack(Rails stack i.e framework)
    • Obviously this is super fast.
  • 7. Implementation
    • Class AboutusController < ActionController
    • cache_page :index
    • def index
    • end
    • end
  • 8. Application flow
    • http://abc.com/aboutus
    • Mongrel can handle 20-50 requests/second. So on an average it can handle
    • 2 million hit per a day. Which is suitable for application.
    Client Apache Mongrel/Webrick
  • 9. With page caching turned on
    • http://abc.com/aboutus
    • Rails will create a cache file in public folder
    Client Apache Mongrel/Webrick Public/aboutus/index.html
  • 10. Serving the cached file
    • http://abc.com/aboutus
    • Apache can handle +1000 requests/second. So on an average 86 million hits a day. So it can handle lot of traffic just by single apache instance
    Client Apache Mongrel/Webrick Public/aboutus/index.html
  • 11. Page caching - limitations
    • This incredible speed up is only available to stateless pages. Where all visitors are treated as same.
    • Page caching ignores all parameters. i.e in the url if we have pagination options there will not be considered by page caching.
    • Page caching is limited to areas where site that will not require authentication.
  • 12. Action caching
    • Action caching works same like page caching. But adds additional feature to run filters before the caching is served.
    • In action caching the incoming web request goes from the web server to rails stack and action pack and do some operations (i.e filters), before running the cache page.
    • So we need action caching, when we need filters to run.
  • 13. Implementation
    • Class ProductsController < ActionController
    • before_filter :authentication
    • caches_action :index
    • def index
    • @products = Product.find(:all)
    • end
    • def create
    • expire_action :action => :index
    • end
  • 14. Application flow
    • http://abc.com/aboutus
    Client Apache Mongrel/Webrick
  • 15. With action caching turned on
    • http://abc.com/aboutus
    • Rails will create a cache file in public folder
    Client Apache Mongrel/Webrick page in cache
  • 16. Serving the cached file
    • http://abc.com/aboutus
    • run filters(authentication)
    Client Apache Mongrel/Webrick Page in caching
  • 17. Fragment caching
    • Fragment caching is used to cache various blocks with templates, without caching the entire action as whole.
    • Mainly used when a page has more parts regularly change and other parts doesn’t change regularly.
    • Fragment caching allows a fragment of view logic to be wrapped in cache block and served out of cache store when next request comes in.
  • 18. Implementation
    • In app/views:
    • <% cache do %>
    • Your code …..
    • <% end %>
    • <% cache(:cache_key ) do %>
    • Your code ….
    • <% end %>
  • 19. Implementation
    • Class ProductsController < ActionController
    • def index
    • @products = Product.find(:all)
    • if !fragment_exist? :recent_posts
    • @recent_products = Product.find(:all, :order => “created_at”, :limit => 3)
    • end
    • end
    • def create
    • expire_fragment :recent_posts
    • end
  • 20. Implementation
    • <% cache(: recent_posts ) do %>
    • <% for product in @recent_products %>
    • <%= product.name %>
    • <% end %>
    • <% end %>
  • 21. Application flow
    • http://abc.com/aboutus
    Client Apache Mongrel/Webrick
  • 22. With fragment caching turned on
    • http://abc.com/aboutus
    Client Apache Mongrel/Webrick Header box #1 box #2 dashboard
  • 23. Serving the cached file
    • http://abc.com/aboutus
    Client Apache Mongrel/Webrick Header box #1 box #2 dashboard
  • 24. Few points
    • The cache helper identifies the fragment to cache. The first parameter is unique name identifier a cache fragment. The second parameter contain a code block.
    • By this way slowest parts of the page are cached and make the web application response time to low…..
  • 25. When to do it?
    • When you can’t use page or action caching.
    • Certain parts of the page are unique to each other.
    Common parts to all pages Common parts to all pages Common parts to all pages
  • 26. configuration
    • To get started make sure config.action_controller.perform_caching is set to true for your environment
    •   By default, caching is disabled for development and test, and enabled for production.
    • config.action_controller.perform_caching = true
  • 27.
    • Thank You
    • Uma Mahesh

×