Rails note Cache System

Source: Internet
Author: User
ArticleDirectory
    • Cache System 1
    • Clear Cache
    • Rails's advice: to prevent new tools such as Google Web accelarator from damaging the Web, all risky operations should be hidden in the post protocol, rather than using get directly, otherwise, once captured by the client (in a session with the real user), the URL will not be safe.
    • Cache System 2
Cache System 1

The cache system takes effect only under production by default.
Modify environment (config/environments)
Actioncontroller: Base. Required m_caching = true | false

Manual Cache

    • Caches_page: xxxaction directly caches the entire page, which is equivalent to HTML
    • Caches_action: xxxxaction only cache action, that is, to execute Filter

The cache is only applicable to static content, and dynamic content is not suitable for the cache

Clear Cache

Manually clear. The parameters they accept are the same as url_for and expire directly according to the URL.

    • Expire_page
    • Expire_action

Auto clear

Implement after_create by specifying a sweeper class <actioncontroller: Caching: Sweeper
After_update and after_destory methods. The input parameter is the model object.

The effective method in controller is the cache_sweeper command.

Batch clear
Pagecache will be placed under APP/public/to clear the corresponding html. For example, write a crontab and control the cache directory and file name as follows:
Actioncontroller: Base. page_cache_directory = "DIR/name"
Actioncontroller: Base. page_cache_extension = ". html"

Rails's advice: to prevent new tools such as Google Web accelarator from damaging the Web, all risky operations should be hidden in the post protocol, rather than using get directly, otherwise, once captured by the client (in a session with the real user), the URL will not cover the cache system 2.

Pass
<% Cache do %>
...
<% End %>

To implement partial Cache

Use expire_fragment (: Action => 'xxx') to clear the corresponding Cache

If a page contains multiple parts
Available
Cache (: Part => "yyy"), add part => "yyy" when clearing.

The cache (: controller =>...: Action =>...) parameter is similar to url_for.

There are four cache storage methods available

    • actioncontroller: Caching: fragments: memorystore. New Direct Memory (not a good idea when data is large)
    • actioncontroller: Caching: fragments: filestore. New (PATH) Direct file
    • actioncontroller: Caching: fragments: drbstore. New (URL) drbserver
    • actioncontroller: Caching: fragments: memcachedstore. New (host) Use memcached server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.