Ruby On Rails 면접 질문과 답변
Question: How can you implement Caching in Ruby on Rails?Answer:Rails offers multiple ways to cache content. Fragment caching is my favorite because it gives you the choice to fragment to pull a portion from the cache and the remaining from a real-time DB call. Say you wanted to show all the orders placed on your website in real time and didnt want to cache that part of the page, but did want to cache the part of the page which lists all products available, you could use this piece of code: <% Order.find_recent.each do |o| %>
<%= o.buyer.name %> bought <%= o.product.name %>
<% end %>
<% CACHE DO %> All available products:
<% Product.all.each do |p| %>
<%= link_to p.name, product_url(p) %>
<% end %>
<% end %>Another technique that works well for static pages is page caching. This technique is often used for home pages and is super fast. class ProductsController < ActionController
CACHES_PAGE:index
def index
@products = Products.all
end
end |
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
Most helpful rated by users:
- What is Ruby On Rails?
- Why Ruby on Rails?
- Explain how (almost) everything is an object in Ruby.
- What are Gems and which are some of your favorites?
- How would you declare and use a constructor in Ruby?