markdown Rails缓存

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Rails缓存相关的知识,希望对你有一定的参考价值。

### Caching Techniques in Rails
* Page Caching
* Action Caching
* Fragment Caching (done by default in Rails)

* To play with caching in development mode (it is done automatically in production)
    * change the setting in `config/environments/*.rb`
    * `config.action_controller.perform_caching = true`

---

### Page Caching
* Rails mechanism which allows requests for a generated page to be loaded by the webserver without
having to go through the entire rails stack.
* Can't be applied to pages that have the `before_action` filters, therefor on pages with
authentication!

---

#### Action Caching 
* Page caching cannot be used for actions that have before filters
* Action caching allows the stack to be hit and lets the filters run before serving the cache.

---

### Fragment Caching
* Different parts of the page can have different levels of caching characteristics
    * Some may need to be expired before others
* Allows a fragment of **view logic** to be wrapped in a cache block and served out of the
cache store when the next request comes in.

```ruby
<% @products.each do |product| %>
  <% cache product do %>
    <%= render product %>
  <% end %>
<% end %>

# Caching each product on a page
```

以上是关于markdown Rails缓存的主要内容,如果未能解决你的问题,请参考以下文章

markdown 升级Rails

markdown Rails新

markdown Ruby on Rails Cheatsheet

markdown 如何部署Rails应用程序

markdown Rails和Backbone.js设置

markdown Rails命令