What is a cache?
A cache -- pronounced CASH -- is hardware or software that is used to store something, usually data, temporarily in a computing environment.
A small amount of faster, more expensive memory is used to improve the performance of recently accessed or frequently accessed data that is stored temporarily in a rapidly accessible storage media that's local to the cache client and separate from bulk storage. Cache is frequently used by cache clients, such as the CPU, applications, web browsers or operating systems (OSes).
Cache is used because bulk, or main, storage can't keep up with the demands of the cache clients. Cache shortens data access times, reduces latency and improves input/output (I/O). Because almost all application workloads depend on I/O operations, caching improves application performance.
How cache works
When a cache client needs to access data, it first checks the cache. When the requested data is found in a cache, it's called a cache hit. The percent of attempts that result in cache hits is known as the cache hit rate or ratio.
If the requested data isn't found in the cache -- a situation known as a cache miss -- it is pulled from main memory and copied into the cache. How this is done, and what data is ejected from the cache to make room for the new data, depends on the caching algorithm or policies the system uses.
Web browsers, such as Internet Explorer, Firefox, Safari and Chrome, use a browser cache to improve performance of frequently accessed webpages. When you visit a webpage, the requested files are stored in your computing storage in the browser's cache.
Clicking back and returning to a previous page enables your browser to retrieve most of the files it needs from the cache instead of having them all resent from the web server. This approach is called read cache. The browser can read data from the browser cache much faster than it can reread the files from the webpage.
Cache is important for a number of reasons.
- The use of cache reduces latency for active data. This results in higher performance for a system or application.
- It also diverts I/O to cache, reducing I/O operations to external storage and lower levels of SAN traffic.
- Data can stay permanently on traditional storage or external storage arrays. This maintains the consistency and integrity of the data using features provided by the array, such as snapshots or replication.
- Flash is used only for the part of the workload that will benefit from lower latency. This results in the cost-effective use of more expensive storage.
Cache memory is either included on the CPU or embedded in a chip on the system board. In newer machines, the only way to increase cache memory is to upgrade the system board and CPU to a newer generation. Older system boards may have empty slots that can be used to increase the cache memory, but most newer system boards don't have that option.
Cache algorithms
Instructions for how the cache should be maintained are provided by cache algorithms. Some examples of cache algorithms include:
- Least Frequently Used (LFU) keeps track of how often an entry is accessed. The item that has the lowest count gets removed first.
- Least Recently Used (LRU) puts recently accessed items near the top of the cache. When the cache reaches its limit, the least recently accessed items are removed.
- Most Recently Used (MRU) removes the most recently accessed items first. This approach is best when older items are more likely to be used.
Cache policies
Write-around cache writes operations to storage, skipping the cache altogether. This prevents the cache from being flooded when there are large amounts of write I/O. The disadvantage to this approach is that data isn't cached unless it's read from storage. That means the read operation will be relatively slow because the data hasn't been cached.
Write-through cache writes data to cache and storage. The advantage here is that because newly written data is always cached, it can be read quickly. A drawback is that write operations aren't considered complete until the data is written to both the cache and primary storage. This can cause write-through caching to introduce latency into write operations.
Comments
Post a Comment