In computer science, a cache is a tiny short-term memory space in a computer with quicker access speed than main memory to fill the gap between slow devices and fast devices. There may be multiple levels of cache, and in general such an architecture is referred to as a hierarchical memory system.
| Table of contents |
|
2 Higher-level caches 3 Design considerations 4 Common cache implementations 5 See also 6 External link |
The cache operates by storing a part of the data, allowing that part to be accessed more quickly. A speed-up is achieved if many accesses to the data can access the data in the cache. The reason caches work at all is that many access patterns in typical computer applications have locality of reference. There are several sorts of locality, but we mainly mean that often the same data is accessed frequently or with accesses that are close together in time, or that data near to each other are accessed close together in time.
One example is a RAM that caches the accesses to the hard drive, so that when two subsequent reads of the same file from the hard disk occur, only one physical read from the disk is performed. Modern disk drives have such a cache built in to the electronics of the drive. Most modern operating systems also operate some sort of disk cache using the computer's main memory.
Caches are also used between the CPU and the (slower) main RAM in modern PC. There are often several levels of cache, with different sizes and access speed. Generally the caches get smaller, faster, and more expensive, the closer to the CPU they are. When the CPU requires data from these caches, there is an increasing penalty to speed according to how far away the cache is.
Caches do not have to be thought about in purely low level/OS terms, software can cache return values that are likely to be re-used in the near future. A good example of this is the BIND DNS daemon which caches domain name replies for a period before going back to the authorative source of the name to IP mapping. Resolver libraries also perform almost exactly the same caching.
Web browsers also use caches. Some browsers implement their own cache of recently visited web pages; this saves having to download them again when you revisit. Most browsers can be configured to use an external proxy web cache, a server program through which all web requests are routed so that it can cache frequently accessed pages for everyone in an organization. Many ISPs use proxy caches to save bandwidth on frequently-accessed web pages.
The search engine Google takes a snapshot of each page examined as it crawls the web and caches these as a back-up in case the original page is unavailable. If you click on the "Cached" link in a Google search result, you will see the web page as it looked when Google indexed it.
When designing a cache there are a number of points to consider:
Accesses to memory or disk are composed of read and write operations. Caching for reading access is far more common than for writing because writing can complicate the consistency of data.
System-level caches
Higher-level caches
Design considerations
A number of different algorithms are used for optimizing the contents of the cache, including to remove the "least recently used" - LRU - contents when the cache is full. Common cache implementations
See also
This article contains material from FOLDOC, used with permission. Update as needed.