Drupal system Cache practices

Source: Internet
Author: User
Tags anonymous apc memcached php code cpu usage drupal drupal cache varnish

Drupal Tutorial: Application of Cache in drupal

Drupal itself executes php code in multiple layers, which results in a large amount of time for it to output content. Cache is a key technology that maximizes drupal performance. Before deciding on the caching mechanism, we must know the type of the website and the types of users who come back to access the site. Not all websites have the same cache mechanism. (Explanation: for this site, the cache technologies mainly include APC and Boost)

The cache technology needs to be differentiated based on different data types and the impact on users. The cache in Drupal can be distinguished by the following two types of users:

Anonymous user
Login user

The html pages sent to anonymous users are the same, but the html pages sent to login users are not the same, for example, "welcome 'user name '". Therefore, we can get a very high Website speed by caching pages for anonymous users. Now let's take a look at the cache technologies in drupal:

Drupal built-in cache

The built-in caching mechanism of drupal allows us to easily expand the drupal site. Data stored in the cache table can be quickly read. Drupal's built-in cache can also be integrated with the back-end cache system to replace the default cache data table. The drupal cache settings are on the admin/config/development/performance page, which includes the following options:

Cache pages for anonymous users: enables page caching for anonymous users.
Cache blocks: enables drupal Block Caching (Block Caching is ignored by page caching ).
Minimum cache lifetime: Minimum cache lifecycle.
Expiration of cached pages: Maximum cache lifecycle.

Use drupal cache api to customize drupal cache

Drupal core provides a cache api to help you store the cache in the cache table. A large amount of data can be stored in a specific cache table. For example, the views module uses cache_views and cache_views_data to store the views cache. The following are several major drupal cache APIs:

Cache_set ($ cid, $ data, $ bin = 'cache', $ expire = CACHE_PERMANENT)
Cache_get ($ cid, $ bin = 'cache ')
Cache_clear_all ($ cid = NULL, $ bin = NULL, $ wildcard = FALSE)

Drupal views cache:

The views module of drupal uses cache_views and cache_views_data tables to store the cache generated by views. By default, the cache is disabled, but you can enable it in each independent views display. It allows us to cache query results and page output for each view display. If you generate a block, you can output the block to the built-in block cache of drupal.

Memcache

Memcache is a high-performance distributed memory object cache system. By maintaining a unified and huge hash table in the memory, Memcache can be used to store data in various formats, including image, video, file, and database retrieval results. It helps you reduce database load and speed. It is usually used to accelerate websites designed for login users. He needs a memcached daemon and a php extension to use the service. However, it cannot support shared servers. Drupal's memcache module integrates drupal and memcache. You need to set memcached as the back-end cache system of drupal to integrate the service into the drupal cache system. Modify the settings file:

$ Conf ['cache _ backends '] [] = 'sites/all/modules/memcache. inc ';
$ Conf ['cache _ default_class '] = 'memcachedrupal ';
$ Conf ['cache _ class_cache_form '] = 'drupaldatabasecache ';
$ Conf ['memcache _ key_prefix'] = 'unique _ key';/Multisite installation/

Opcode Cache

There are several php plug-ins that can convert program code to bytecode. Bytecode can skip the second re-compilation process. It can reduce page loading time and cpu usage. This technology is called Opcode Caching. APC (Alternative PHP Cache) is one of the most commonly used php Opcode Caching extensions. (This site has an installation tutorial) Zend Opcache is another available php extension. By default, it is compiled in php v5.5 +. It contains many advanced features not available in apc, but does not support user caching.


Reverse Proxy-Varnish

Varnish is a high-performance open source HTTP accelerator. Varnish plays the role of the web server and the user's intermediary agent. When Varnish receives a page request, it first checks its internal cache. If a cached page is found, Varnish returns the page to the user. Otherwise, Varnish requests content from the original web server area. Drupal's varnish module integrates Drupal and Varnish HTTP accelerators. You need to add the following parameters to your configuration file/etc/varnish/default. vcl:

Backend default {
. Host = "127.0.0.1 ";
. Port = "8000 ";
 }

Note: the Page cache lifetime option on the drupal performance Page usually defines the Varnish cache expiration period.

Boost

Drupal's boost module provides page caching similar to Varnish. When a user requests content, he returns the previously generated static html page to the user, avoiding secondary generation. If the following information is displayed, your module takes effect. (You can right-click to view the source code of the page, and we also use boost to accelerate the website.) boost is very effective for anonymous users. You can use Memcached to accelerate login to users.
Content Delivery Networks (CDN)

CDN stands for Content Delivery Network (CDN. The basic idea is to avoid bottlenecks and links on the Internet that may affect data transmission speed and stability, so that content transmission can be faster and more stable. The Drupal cdn module can accelerate your drupal site. The only pity is that cdn may cost you a certain amount.

Conclusion

The above technologies provide you with more cache options. Generally, you can configure the best cache practices. However, it is necessary to select technologies and modify configurations based on the characteristics of different sites.

Appendix drupal official website tutorial https://www.drupal.org/node/627252

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.