×
Community Blog Cache Definition: What Is Cache

Cache Definition: What Is Cache

Cache is one of the most important tools programmers use to create a high-performance, high-concurrency system.

What is Cache

Cache is actually a small-capacity local memory set up in order to regard the large-capacity internal memory composed of DRAM as a high-speed memory, and is generally composed of high-speed SRAM. This kind of local memory is CPU-oriented, and it is introduced to reduce or eliminate the impact of the speed difference between CPU and memory on system performance.

Cache usually stores a copy (copy) of part of the content in the internal memory. The copy of the content is the data and program codes that have been used by the CPU recently. The effectiveness of Cache is to take advantage of the local locality of the program's access to the memory in time and space, that is, for most programs, a specific area will be intensively and repeatedly accessed within a certain time slice. For example, the operations of PUSH/POP instructions are executed sequentially on the top of the stack, variables will be reused, and subroutines will be called repeatedly, etc., which are practical examples of this local culture. Therefore, if for a specific time slice, replace the low-speed and large-capacity internal memory with the Cache connected to the local bus, as the area where the CPU concentrates and repeatedly access, the performance of the system will be significantly improved.

When the system is powered on or reset, there is nothing in the cache. When the CPU sends out a set of addresses to access the internal memory, the content of the accessed memory is "copied" to the Cache at the same time. After that, whenever the CPU accesses the memory, the Cache controller must check the address sent by the CPU to determine whether the address unit to be accessed by the CPU is in the Cache. If it is, it is called a Cache hit, and the CPU can read/write it at a very fast speed; if it is not, it is called a Cache miss. At this time, it needs to be accessed from the memory and placed adjacent to the current access. Copy the contents of the storage area to the Cache. When a miss occurs, memory access may require more waiting cycles than access to memory without Cache, which will reduce the efficiency of the system. The call and jump instructions in the program will cause non-regional operations, which will reduce the mission rate. Therefore, improving the hit rate is the main goal of Cache design.

Cache function

The speed of the CPU is much higher than that of the memory. When the CPU directly accesses data from the memory, it has to wait for a certain period of time. Cache can save a part of the data that the CPU has just used or recycled. If the CPU needs to use this part of the data again, it can Call directly from the Cache, which avoids repeated access to data, reduces the waiting time of the CPU, and thus improves the efficiency of the system.

The difference between register, cache and memory

Register: The basic unit in the cpu is at the same level as the arithmetic unit in the cpu. Data storage directly processed by the arithmetic unit. There are registers in all CPUs from ordinary single-chip microcomputers to intel.

Cache: Generally, ordinary MCUs do not have caches. Some powerful personal computers or mobile phone chips have caches. The caches generally use SRAM static random access memory, which is very fast. It is usually the case that the used data read from the memory is put into the cache when the computer is working, so that it can be found quickly when it is used next time. However, the cpu generally does not directly access the cache, but first puts the cache into the register, and then operates.

Memory: Generally, ordinary MCUs have no memory, and the memory is generally external, and the cache and registers are usually integrated inside the cpu. The memory generally uses DRAM dynamic random access memory, which is slower. The working cpu will first go to the cache to find the data it wants, if not, it will go to the memory to read it.

Where is the cache location?

The arithmetic units, controllers, registers, and cache are all encapsulated inside the CPU. The CPU as a whole fetches data from the memory, and the data in the memory comes from the external memory.

On the whole, cache is a bridge between CPU and memory, used to balance the speed difference between high-speed devices (CPU) and low-speed devices (memory).

Speed from fast to slow: register>cache>memory>external storage

Unit price per storage unit from high to low: register>cache>memory>external storage

Storage capacity from high to low: external storage>memory>cache>register

Related Articles

Building Enterprise-Grade Caching Service on Alibaba Cloud

In this article, we will discuss about server-side caching technologies, especially Redis, and show you how we can deploy a Redis caching server on Alibaba Cloud.

Caching: Essential Skills for developer

This article provides a systematic walkthrough to understand what cache is, why it is significant, where it is located in the service process, and when it is required.

Related Products

ApsaraDB for Memcache

ApsaraDB for Memcache is a managed memory based caching service, which supports high-speed access to queries and data. ApsaraDB for Memcache improves the response of dynamic websites or applications by relieving the load on the backend database as cache data is stored in-memory.

Log Service

Log Service is a complete real-time data logging service that has been developed by Alibaba Group. Log Service supports collection, consumption, shipping, search, and analysis of logs, and improves the capacity of processing and analyzing large amounts of logs.

0 0 0
Share on

Alibaba Cloud Community

875 posts | 198 followers

You may also like

Comments

Alibaba Cloud Community

875 posts | 198 followers

Related Products