Getty Images/iStockphoto

Cache vs. RAM: Differences between the two memory types

Cache memory and RAM both place data closer to the processor to reduce latency in response times. Learn why one can be faster, along with other key variables in cache vs. RAM.

RAM and cache memory are both fast, volatile memory technologies that play a pivotal role in computing. So what's the key difference between the two?

To borrow an adage from real estate: "Location, location, location!"

RAM stands for random access memory. Any file or application actively in use on a computer is stored in RAM primary memory. Cache is a smaller memory configuration reserved from main memory to make computer operations more efficient. The cache is nearer to the central processing unit (CPU) than main memory, enabling optimal performance when users access certain types of data.

Volatile memory can't retain data without continuous access to a power source. Devices made with nonvolatile memory -- which store data even when a power source is lost -- may be added as an external or secondary cache to most computers. However, this article compares RAM as storage memory with RAM as a disk cache.

What is RAM?

Computers are equipped with data storage and memory components. HDDs or, more commonly, SSDs provide internal data storage, and RAM provides the working memory for applications and files.

RAM primary memory acts as fast internal storage for the CPU. Desktops, laptops, smartphones, smart TVs, tablets and other computing devices contain RAM. Dynamic RAM (DRAM) is a type of RAM that holds the OS and application data to enable the CPU to access them quickly.

RAM has its limits. Once a computer's RAM fills up, its processor must create virtual memory to compensate for the shortage of physical memory.

RAM is built into the motherboard and accessed by the CPU across a motherboard backplane. A RAM memory component is made from a series of semiconductor chips that comprise the memory cells. The cells handle reads and writes of data. When users work on a Word document, any changes are stored in RAM. Typically, when the user closes that document, the data is backed up to the computer's internal drive storage, a secondary storage device or the cloud.

When booting a computer, the OS places application code and instruction sets in RAM to access the drive and wake up other components. "Random access" means RAM cells can be accessed in any order, which enables users to move easily between multiple applications -- for example, to shift back and forth between different browser tabs.

In the classic von Neumann computer, RAM was the "chalkboard" where processors did the math of a program. Placing the data store closer to the processor avoids data requests and responses that have to traverse the motherboard bus. This reduces the wait time or latency associated with processing and improves chip performance.

But RAM has its limits. Once a computer's RAM fills up, its processor must create virtual memory to compensate for the shortage of physical memory. Virtual memory is created by temporarily transferring inactive data from RAM to disk storage, using active memory in RAM and inactive memory in hard drives to form contiguous addresses that hold an application and its data.

Flash memory provides an additional cache at the magnetic media level -- on disk controllers -- to lower latency, especially as disk capacities expand and access to data increases. There is speculation that flash storage, especially SSDs, will displace magnetic hard disks as production storage media.

What is cache?

The term cache generally refers to hardware or software that temporarily stores frequently accessed data.

Cache is a memory component that usually is part of the CPU, or part of a complex that includes the CPU and an adjacent chipset. Memory holds data and instructions that an executing program frequently accesses -- usually from RAM-based memory locations.

The cache provides a small amount of faster memory that's local to cache clients, such as the CPU, applications, web browsers and OSes, and is rapidly accessible. L1, L2 and L3 are different levels of cache memory. All types of cache memory are used to reduce access times and latency, while improving I/O. Because almost all application workloads depend on I/O operations, caching improves application performance. Faster data access and I/O also improves computer performance.

Because it's built directly into the CPU, L1 cache memory provides the fastest possible access to memory locations, which supports faster CPU performance. L2 cache can be integrated in the processor, but more frequently is placed on a chip adjacent to the CPU, as is L3 cache.  As a result, the adjacent chips that hold L2 and L3 memory cache can be somewhat slower and usually have a direct pathway to the CPU to optimize performance.

Cache vs. RAM: What are the differences?

There are several key differences between RAM and cache memory.

Chart comparing RAM and cache memory
  • Usage. RAM provides short-term access to applications and files running in the background. Insufficient RAM will cause a system to labor to process data. But RAM is expensive and should be added only if the performance improvement justifies the cost. Cache serves recurring data to the CPU whenever it's requested. This includes data with common access patterns or calculations that would take too long to compute on a repetitive basis.
  • Capacity. Most modern computers are built with 64-bit computer architecture and 32 GB of RAM, with additional RAM available via expansion cards. Additional cache memory is available in capacities up to 512 KB.
  • CPU proximity. Comparing cache vs. RAM, both are situated near the computer processor. Both deliver high performance. Within the memory hierarchy, cache is closer and thus faster than RAM.
  • Cost. Cache is made of static RAM (SRAM) cells engineered with four or six transistors. SRAM is more expensive to manufacture than other types of computer memory and storage, including HDDs and SSDs.
  • Operations. Cache provides a direct memory interface to the CPU. RAM cells can be accessed directly in any order.
  • Performance. CPU cache is built into the CPU or on an adjacent chip. Its memory access time reportedly is 10 to 100 times faster than RAM, requiring only a few nanoseconds to respond to the CPU request. RAM data access is faster than read-only memory and mechanical storage devices, such as hard disks and tape. Magnetic media delivers I/O at rates measured in milliseconds.

This article was originally written by Jon Toigo and most recently expanded by Garry Kranz.

Next Steps

Dig Deeper on Flash memory and storage