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