The speed of your website is crucial for a good user experience. Therefore, it is important to keep the load on your resources, such as RAM, disk space, CPU and network, to a minimum.
For this, there is a clever way to use your server and network as efficiently as possible while maintaining the speed of your website: caching.
Caching allows you to temporarily store data so that they can be accessed faster. By storing temporary copies of a website, the computer no longer needs to regenerate the data. This makes the website faster.
The purpose of caching is to make websites and web applications load faster. Fast loading times and an optimal user experience are therefore the main benefits.
As fewer resources are used, your website will be more stable in the event of large traffic peaks.
A faster website also helps improve the SEO (Search Engine Optimization) of your website.
Why is caching so much faster?
When an Internet user wants to visit your website, a request is sent (via the Internet) to your server to display the content of the page. This request must be processed and imposes a certain load on RAM, disk space, CPU and network. This causes delays in returning the content.
Caching helps reduce this delay by temporarily storing frequently requested data in a different location and in a simplified structure. Since these data are stored separately, they no longer need to be requested from the server when the website is visited again. This ensures that the page is displayed much faster.
The copy of your website that is stored in the cache is not automatically updated when changes are made to your website. It is therefore possible that your visitor will see expired web pages. This is particularly problematic if the content of your website changes frequently and quickly, e.g. for news websites.
The cached copy has a limited validity anyway. You can usually set this caching period yourself. The more frequently you make changes to your website, the shorter the data should stay in the cache. Once the cache validity has expired, the application will have to request the data from the server again.
When the source data are edited while they are still in the cache, the application must remove the items in question from the cache itself. In most cases, this is done in the logic executed when adding, deleting or editing the source data. The application then looks for the right location in the cache to remove the items in question.
This explicit action prevents websites or applications from displaying output that is no longer valid.
In principle, you can cache any type of data. But for the cache to work efficiently and to avoid extra complexity, you should use caching to store data that is very resource intensive to compute:
In concrete terms, these data are usually:
All computer systems automatically cache data. Even when you load files from the hard disk, the operating system will keep parts of the file in RAM. Database systems do the same. Unfortunately, the operating system does not know the context of your application and specialised caching systems are thus required to achieve the desired result.
Combell offers the following caching systems:
An HTTP cache that caches entire pages. Works out of the box for static web pages. The integrated VCL programming language makes it possible to create rules for caching dynamic and personalised pages. Combell offers Varnish configuration templates for popular platforms such as WordPress, Drupal and Magento.Learn more about Varnish
A distributed key-value store that can be used to store temporary data. It is known for its speed and flexibility and needs to be accessed from the application. Platforms such as WordPress, Drupal and Magento offer integration options for Redis to store dynamic data.Learn more about Redis
An integrated cache that reads PHP files, compiles them and stores them in memory as machine code. Enabled by default with your Combell web hosting package, which means that no technical knowledge is required. Immediately improves the overall performance of your PHP code, but only has an indirect impact on the loading times of pages.
A local key-value store that is part of your PHP installation. Enabled by default with your Combell hosting package. Also offers integration options with the most common frameworks and CMSs. Comparable to Redis, but with fewer features.
Each type of cache has specific objectives. It makes no sense to enable all the caches at once. That does not guarantee better results and also increases the complexity of the system.
Select the right type of cache
In that case, you should enable OPcache. With Combell, OPcache is enabled by default for our web hosting customers.
It is recommended to cache as many entire web pages as possible. And for this, it is best to use Varnish. Static pages or pages with few personalised elements can be cached very easily using Varnish. Varnish also offers numerous integration options with CMSs and frameworks.
Varnish also includes a programming language, which can be used to determine what must be cached and what must not.
Some pages cannot be cached in their entirety because they contain personalised elements. Just think of the online shopping cart or the checkout process of a web store. These pages are unique per visitor. However, some data from these pages can be cached, which reduces the load on the database or the file system.
Do you want to retrieve data from a database, a file on the disk or via a web service? If so, you should enable Redis or APCu.
Are the data only used by PHP?
If so, APCu will suffice. The application code will still be executed, but access to certain data will be cached.
Do other systems also need to access the cached data?
In that case, Redis will be the most suitable caching technology. Redis offers advanced data types, more commands, as well as the opportunity to control the behaviour through LUA scripts.
Depending on your CMS or framework, there may be ready-made integration options for Redis or OPcache.
Combining caches is possible, but make sure you do not overdo it. Because you might then display expired data. Be sure to clear the caches when the source data are updated.
Each caching system can determine how long items should be kept in the cache and allows you to remove items from the cache.
For years, Combell has been committed to achieving fast loading times and optimal user experience by means of caching solutions. Together with you, we look for the best solution for your website or application. Our experienced specialists are responsible for selecting and implementing the best caching solution.