What is a cache and how does intermediate memory work?

In digital systems, data is constantly in demand, such as data from a database, web server or hard drive. Each access to data takes time, which is why it is worthwhile to reduce this access time as much as possible. This increases the number of hits that can be processed per unit of time. In addition, the short reaction times ensure a good user experience.

The cache dramatically reduces the access time to previously accessed data, which is why this intermediate memory system is used in almost all systems and applications. Find out what this technique is, its advantages and disadvantages, as well as the different types of caches that exist.

Summary

What is a cache?

What is the purpose of a cache?

How does a cache memory work?

Advantages and disadvantages of the cache

What are the different types of caches?

What is a cache?

The term cache refers to a digital intermediate memory system that stores the accessed data for later access. During subsequent visits, the cache responds to requests, so there is no need to contact the original application. Web servers are a good example of this: they have their own cache, which can temporarily store website content. If this website is visited again later, it can be loaded faster, because the data is stored in the cache and the server does not need to send a request.

Definition

Cache: A cache is an intermediate memory that stores data for later access. It reduces the access time to this data. The cache is an invisible layer between the user and the data source. The process of saving data to the cache is called "Caching" or "Caching".

To make the principle of caching more understandable, let's use a medical example.

Imagine dental treatment or surgery. The doctor asks his assistant for a resource: a scalpel, a disinfectant or even dressings for example. If the resources are already ready, the assistant can react immediately and take them to the doctor. Otherwise, the assistant must locate the requested resource in the medicine cabinet and then take it to the doctor. After use by the physician, the resource is kept close at hand by the assistant for quick later access.

In their use, individual resources are not completely independent of each other: if the doctor needs a disinfectant, he will probably also need a compress, and a needle is of no use cordless. The wizard will prepare the resources used together in advance in order to minimize the access time to the resources.

As you can see, making available resources that are often used is a very useful process on a daily basis. In the digital world, these related processes are grouped together under the term “caching”.

What is the purpose of a cache?

The primary purpose of a cache is to reduce the access time to important data. The important data are:

Data used often: In this case, it would be inefficient to repeatedly reload the data from the slower memory behind the cache. Instead, data is delivered faster from the cache.

Data generated by complex processes: some data is the result of complex processing or the data must be assembled from different composites. In this case, it is advisable to store the final data in cache memory for later searches.

Data that is needed together: in this case, it would be inefficient to load the data only when it is needed. It makes more sense to keep the data together in the cache.

What is a Cache


How does a cache memory work?

Now let's come back to the concrete operation of the cache. In particular, we will address the question of how an intermediate memory works and where it is located.

Basic diagram of a cache

A request for access to a resource is made to the system or software that has a cache.

If this resource is already in the cache, the cache provides the resource. In this case, we speak of "Cache Hit" or "Cache Hit".

If the resource is not in the cache, it is first downloaded from the system where it is in staging, and then delivered to the client. In this case, we speak of "Cache Miss" or "Cache fault".

If that same resource is required again later, it can be cached, so it's a "Cache Hit".

How a cache works: example of a web cache.

The general operation of a cache is illustrated by the specific example of a web cache.

The image illustrates the basic operation: a client sends a request to a server (1) to access a resource. In the case of a "Cache Hit", the resource is already in the cache and is delivered immediately to the customer (2). In the case of a "Cache Miss", the requested resource is not in the cache and is therefore required from a server (here a database) (2). As soon as the resource is available (3), it is delivered to the client (4) and stored in the cache for later use.

Where is the cache?

The main feature of the cache is that it is hidden. This fact is reflected in the origin of the word: the word "cache" comes from the French, from the verb to hide.

The cache is invisible to the user and is located just before the data store. This means that the user does not need to know the properties of the cache. The user sends a request to the data carrier and does not notice that the cache is providing the resources.

How many caches are there in a standard configuration?

Usually, several caches are active in a digital system.

Consider accessing a website: the browser communicates with a server and sends a request for a series of resources. As long as the content of the page is not displayed in your browser, the components of the page generally go through the following caches: processor cache, system cache, browser cache on the device as well as the CDN (Content Delivery Network) and the web cache on the server site.

Advantages and disadvantages of the cache

Whether or not an application has a cache is in principle at the discretion of the developer. Here is a compilation of the pros and cons of a staging solution.

Benefit: Considerable improvement in speed

One potential benefit of using a cache is the dramatic increase in speed. Acceleration per hundred is common. The acceleration is effective only for repeated viewing of data. The actual gain will therefore vary greatly depending on the situation and the application.

Benefit: Reduced system load behind the cache

Since a cache can greatly reduce the loading time, the load on the system is considerably reduced.

Take for example a dynamic HTML page generated from a PHP template: you access a database to generate the page. This access is relatively resource-intensive. Additionally, it is not uncommon to calibrate database servers, which is why accessing databases as a "bottleneck" can limit overall system throughput. In this case, it is advantageous to store the generated HTML page in a web cache in order to use the capacity of the database server for other tasks.

Disadvantage: invalidating the cache is a difficult task

 Quote

“There are only two hard things in Computer Science: cache invalidation and naming things. "

("There are only two difficult things in computing: cache invalidation and naming.")

The term cache invalidation refers to the decision of when the cached data is no longer current and needs to be updated. Let's take the medical example above: the assistant acts as a hiding place for the doctor by making available resources already used for later use. Since there is little space on the shelf, the physician's assistant is continually tidying up during treatment. The resources used should be discarded and replaced. It may also happen that the assistant withdraws a resource that the doctor will need again. This case can be considered a “Cache Miss”. The assistant must then locate the requested resource.

Since a "Cache Miss" is expensive, the optimal caching strategy aims to avoid it as much as possible. It can also happen that the cache data is no longer up to date. This problem can be further exacerbated when multiple hierarchically adjacent caches are active. It can be difficult to determine when the data in the cache is out of date.

If a cache provides data that is no longer up to date, it usually causes various problems on the user side: the visited website has displayed errors or fragments of the past appear while retrieving the data. It can be difficult to locate the problem and in this case, clearing the cache is often the best solution.

To learn more about the internet Click Here

What are the different types of caches?

Caches are made up of hardware and software components. A hardware cache is fast intermediate memory that reduces access times to the data memory behind it. In principle, hardware caches are always very small compared to the total size of the caches.

On the other hand, the caches implemented in the software can even exceed the size of the resource in front of which they are. This is especially true if multiple versions of a resource are in the cache.

Here is an overview of the resources that are typically cached. The size of the cache memory, the cache access time and an indication of the speed of access to the resource in the absence of cache memory are displayed.

Post a Comment

Previous Post Next Post