What Is a Cache?
Author: Domeny.ForSale editorial team Published
In brief: A cache stores data that may be needed again so it can be accessed more quickly. It means a browser does not have to download the same files every time, and a server does not have to repeat some calculations. Sometimes, however, the stored data is outdated — refreshing it or clearing the relevant cache can help.
How does a cache work?
When an application needs particular data, it can first check whether it has it in its cache. If it finds a copy that it can use under the applicable rules, it reads that copy instead of accessing the source. This is called a cache hit. If there is no copy, or the copy cannot be used, the application retrieves or calculates the data again.
Imagine browsing several products in an online shop. The shop’s logo, some icons and the file that defines the page’s appearance are shared across successive pages. The browser can keep them after the first download instead of downloading them again with every click.
A cache does not have to be stored in RAM. Depending on its purpose, cached data can also be stored on disk or on a separate server. The goal is the same: to reduce the time it takes to access data and the work needed to obtain it.
Where do you encounter caching in everyday use?
Caching operates at various levels. Distinguishing between them helps identify why a website or application is still displaying an old version of the data.
| Cache type | What it can store | What it does |
|---|---|---|
| Browser | Images, stylesheets and scripts | Reduces repeated downloads of website resources |
| Application | Thumbnails, downloaded content, query results | Speeds up content display and repetitive operations |
| Server | Ready-made pages or calculation results | Reduces the load on the system serving the website |
| CDN | Copies of files or website responses | Delivers content from a distributed network of servers |
| DNS | Responses containing information such as a domain’s IP address | Reduces repeated queries for a server’s address |
A CDN is a network of servers that helps deliver content to users. DNS, meanwhile, is a system that makes it possible to determine, among other things, the IP address corresponding to a domain name. A DNS cache does not store a website’s appearance — it remembers responses relating to its addressing.
Processors also have their own caches, providing fast access to frequently used data and instructions. This is not, however, the cache you clear in your browser settings.
Why does a cache sometimes display outdated data?
A cached copy does not always change at the same time as the source. If a website owner replaces an image, the browser may still use the previously downloaded file. Similarly, a server may return a saved version of a page instead of generating it again.
One way to control freshness is TTL, or time to live: the period for which a cache entry remains valid. Once it expires, the system may retrieve new data or check whether the existing copy is still up to date. Expiration alone does not necessarily mean that the file is immediately deleted from disk.
Another mechanism is cache invalidation: marking a stored copy as outdated or deleting it after the data changes. When publishing new website files, URL versioning is also used, for example by changing style.v1.css to style.v2.css. The new URL distinguishes the new resource from the previously stored copy.
Data such as the contents of a private account or shopping cart requires particular care. A cache shared between users should not give one person access to content intended for another. This is a matter of website configuration and cannot be resolved by a visitor clearing their browser cache.
When and how should you clear a cache?
Clearing a cache makes sense when a website looks wrong, does not display published changes, or an application is using corrupted temporary files. It is not necessary as a daily step to speed up your device. After cached copies are removed, opening a website for the first time may take longer and require its resources to be downloaded again.
If you suspect a problem with a website’s cache, follow these steps:
- Refresh the page. If that does not help, use your browser’s option to refresh while bypassing the cache. A normal refresh does not always force every file to be downloaded again.
- Check the website in another browser. A difference may indicate a local problem, although extensions or settings could also be the cause.
- Clear cached images and files. Check the time range and the selected options. The names of these options vary by browser; deleting all site data may also remove login information and settings.
- If you manage the website, check the server and CDN caches. Deleting local files does not remove copies stored by these systems.
After a domain’s IP address changes, the DNS cache may be relevant. Clearing it on your computer does not remove entries from the caches of the DNS servers used by your provider, so it does not guarantee that you will see the change immediately.
Cache, cookies and application data are not the same thing
Cookies are small pieces of data that a website can save in your browser, for example to identify a user’s session. A cache is primarily used to reuse resources. Clearing only cached files usually does not log you out of websites, but deleting cookies may do so.
In application settings, the “clear data” option is usually broader than “clear cache”. It may remove settings, login information or locally stored content. Before using it, read the system message and make sure important files have been saved or synchronised.
When a problem affects a single website, start by refreshing it and removing only its cached resources, if your browser offers that option. Do not delete all browsing data before trying a less intrusive solution.
