What is the cache and how does it affect server performance?

Author: HOSTTEST Editorial   | 29 Oct 2020

A cache refers to an intermediary storage for data that is created or frequently requested by an operating system or a program. It can be either a local file or a limited space in the random-access memory (RAM) where a computer temporarily stores information to access it more quickly. The cache can hold various formats, ranging from running processes to databases and extracted archives. The cache is considered a standard tool - it is used on a desktop PC, in Virtual or Dedicated Servers, across different operating systems, and sometimes specifically for individual programs.

What is the purpose of a cache memory?

Generally, the cache's task is to store data that will be needed within a foreseeable timeframe. For a desktop PC, this includes information such as the results of calculations, variables, programs, and archives. The advantage of this approach lies in the increased speed at which a computer can perform operations because the cache optimises loading times. For instance, in repetitive tasks, the solution is immediately available without the computer consuming resources for the calculation. The cache significantly influences a computer's performance with its speed and size. This performance varies greatly depending on the storage medium it uses - the random-access memory (RAM), an SSD, or a slower HDD.

What is the purpose of caching on websites?

Both the server and the client use their own cache on a website. Both serve the same purpose: to enable a rapid page load. To achieve maximum speed, the cache of individual programs - whether browsers like Firefox and Chrome or servers like Apache 2 or NGINX - contains various information, including:

  • Entries from the Domain Name System (DNS) for address resolution
  • Embedded content of a webpage such as images, videos, or interactive elements
  • Scripts and configurations for display - e.g. HTML code or CSS stylesheets
  • Databases for user differentiation based on specific criteria - e.g. geoblocking
  • Source code for dynamic webpages - mostly PHP scripts
  • Global configurations for the website
  • External programs or parts of their compiled routines, e.g. MySQL or MariaDB server or their interfaces

A web server like NGINX or Apache also stores code processed by the PHP interpreter in the cache if it can be applied universally and not user-specific. When identical requests are made, the server uses these templates and only needs to process certain individual elements - for example, the shopping cart in an online shop - separately.

How does a cache work?

A cache contains data that has been needed or calculated in the past. When a program like Apache 2, NGINX, or the Firefox browser accesses data and uses a cache, it first sends a request to check if the data is already available. If the resources are present, it results in a hit, and the information is loaded without delay. If the resources are not yet available (miss), the operating system loads them from the internet or from the disk, or a program like a PHP interpreter generates them, for example, through a MySQLi query. If the software needs this data again within a specified time (Time to Live, TTL), it can use the stored routines, files, or results instead of performing a time-consuming reload.

Why do servers benefit from a large amount of RAM?

A dedicated Linux server or VPS hosting always aims to utilise the RAM as fully as possible to reduce access times and optimise the processor's computing power. For websites with numerous users, a large cache in the RAM ensures that most required information is available almost immediately. Additionally, the RAM must also store all data related to individual connections and, not least, the operating system. When the operating system has low free resources, it moves them to areas of the disk that complement the RAM. However, due to higher access times, the positive effects of this approach diminish significantly - hence, it is desirable to always keep the entire cache in the RAM.

Photo: John Howard on Pixabay

Write a comment


More web hosts


More interesting articles

Time To First Byte explained: How to measure and improve TTFB

This article provides a comprehensive insight into the importance of TTFB and practical ways to measure this metric and ...

Fastest Web Hosting Provider in Germany: Who Delivers the Best Performance in 2025?

This article takes a close look at the fastest web hosting providers in Germany and evaluates them based on important me...

Lazy Loading - What's Behind It?

The loading times of a website should be as minimal as possible. How exactly can Lazy Loading help with this?

Server Speed - What Matters and How to Measure It?

Why is the speed of a server so important, how to measure server speed, and how can it be increased?

Website not reachable - Causes and Measures

Anyone who operates their own website for a longer period of time will sooner or later be confronted with downtime. But ...

What is HTTP/2 and does it bring more speed?

Thanks to the new HTTP/2 connection protocol, websites can be loaded faster in the future. Most internet browsers and we...