How to up your Cache for DrupalPosted by On


Drupal makes use of its versatile and powerful framework by extending its modules and interfaces as far as possible. Drupal developerscan make use of the modules that are labeled Core and Contributed. These modules can be used to achieve the desired results for their websites. Cores are modulesthat have been included in the initial Drupal installation. Contributed are modules that have been developed and distributed in the Drupal communityby programmers. Contributed modules are usually free to download online or available through the Drupal community. Thousands of Drupal modules are available and they help to extend the usability and the functions of a website.Drupal is very useful for creating High Performance Dynamic websites, but this can be a disadvantage to the server. A simple surge of users requesting pages at the same instance can cause the site to crash if the website is not configured properly to handle it. Dynamic content usually requires more work from the backend than static content. By dynamic content, I mean moving pages, videos or a newsfeed that updates every few seconds.

drupal-upgrade

A lot of websites strive on traffic to gain revenue. They run pay-per-click advertisements or e-commerce applications that profit with increased user traffic. Downtime on an e-commerce website during a traffic surge means the website owner will miss potential customers. Due to Drupal running so many modules simultaneously and multi-tasking, it requires some kind of program to protect the server from crashing during peak loads. One of the most effective ways to lower the server load is to set up the cache.

What is Caching?

Caching is the action of storing a certain page or block, so that it can be presented to the users when it isrequested again. Caching lowers the load on servers by serving copies of pages to users when they visit a frequently used web page. A Cache can be a very significant tool if it is setup properly. The key with Caching is that the administrators can watch which pages are the most visited and setup the cache accordingly. An anonymous home page for a website is a good page to cache because it is the first page that will get loaded upon a user visit. Even if you are a registered user, more than likely, you will have to sign in from the anonymous home page. A bad page to cache is a user profile on a bulletin board. User profiles are not usually visited a lot unless the link is posted through an external source which has a lot of traffic or users.

Drupal Caching

Standard Drupal Caching gives you options to further simplify the setup. There is a box that can be checked that says “Cache pages for anonymous users”. When this box is checked, only pages for anonymous users will be cached. Then, there is a box called “Block Caching”. Blocks are basically defined regions which contain content on a web page. Block Caching is the act of serving blocks from the cache instead of a whole page. Let me give an example where this might be useful. A user page for a social media website might have a block with home, friends, messages and a search link. Every page on the website would have this block on it which never changes. Well, this is where block caching comes in handy. This block can be saved in the cache bin and served for every registered user as they will always use it. So, the block has been cached and the rest of the page will be requested from the server. Then, there is a drop down menu under “Minimum cache lifetime”. This defines the life of the caches saved.Once the cache lifetime expires, the next user to load the cached page will experience a longer load time at that instant, and then the page is cached once again. The drop down menu under “Expiration of cached pages” controls the amount of time an external cache service can use an old page for. This applies to external cache modules such as APC or Varnish.

Caching with Boost

Boost is a contributed module that caches static pages very well. It is a very good option for sites that have a lot of anonymous traffic. It works by serving static pages to users for frequently requested anonymous content. Boost manages its cache box with its built-in crawler that regenerates cache to diminish the initial slow page loading that users would experience. This ensures that expired content is replaced in the cache box.

Setting up Reverse Proxies

A reverse proxy is a proxy that is configured as a face for the server. This can be a useful tool for security and lowering loads on the server. The difference between a normal or forward proxy and a reverse proxy is that the users trying to access the server do not necessarily know that they are accessing a reverse proxy. It is controlled by the server. A forward proxy is requested by the user, so the user knows that s/he is using a proxy. An example of a forward proxy is a website that allows you to view websites restricted by your IP or administrator. A great Reverse Proxy is the Contributed module Varnish.

Using APC (Alternative PHP Cache)

Drupal is written in the programming language PHP. The script is complied at the time of execution. APC stores a copy of the script pre-compiled. This saves time by serving a pre-written script and lowers the work done by the server. APC should be configured so as to best fit your website’s needs. Here are the meanings of the directives:

apc.enabled = 1:The 1 signifies that APC is turned on. A 0 would turn off APC.

apc.shm_segments = 3: This means that there are 3 segments of memory for PHP to cache in.

apc.shm_size = 48:For each segment defined in ‘apc.shm.segments’, there is 48MB of space.

apc.cache_by_default=1: The ‘1’ signifies that PHP will cache every page by default. A ‘0’ turns it off.

apc.filters= “   “: This directive is tricky. If ‘apc.cache_by_default = 1’, then APC will cache every page except the ones defined in ‘apc.filters’. If ‘apc.cache_by_default = 0’, then APC will only cache what is defined in ‘apc.filters’.

apc.stat= 1: The ‘1’ tells APC to check if the cached data has been changed or updated. The ‘0’ tells APC not to check.

apc.ttl = 3600: This configures the time that a page is cached for in seconds. Therefore, the 3600 represents 3600 seconds or 1 hour.

It is important to set the cache properly when building high performance Drupal websites with a lot of dynamic content.It can help to protect your website from crashing under traffic surges. Take the time to study the pages most visited, and to adjust the settings of the cache accordingly.

Maria John is an avid hiker that lives & breathes the outdoor life, capturing every moment with her childhood passion of photography. Following her interest in business, she writes columns for Orange county Drupal developers.

Web

Orange county Drupal developers

Comments are disabled.