Definition: What Is a Cache?
In computer science, a cache is a storage location used to temporarily store data used by servers, apps, and browsers to speed load times. There are many types of cache. Depending on where you look for them, almost any machine, be it software or hardware, will have and use a kind of cache.
What Is Cached Data?
Cached data is information stored in a specific location used to speed up gathering and transferring data. In the case of a website, the cache would allow you to load certain resources without downloading them from the server every time you access the page, like fonts or icons.
For servers, cached data can be dynamic data saved as simple HTML to speed up the page load time.
Types of Caches
Depending on your use case, you might utilize one of these four main types of caches:
Web Browser Cache
This storage is done in the browser. All browsers have a local storage that they use to retrieve previously accessed resources. This type of cache is private since stored resources are not shared. Browsers cache data such as entire web pages to speed up the loading times.
This storage, also called “intermediate caching,” is done between the client and the origin server on the proxy server. Proxy cache is a shared cache used by multiple clients and usually maintained by providers. Proxy servers allow data to be shared with more users and use cache to avoid retrieving data from the database every time it’s requested.
Also called “reverse proxy,” gateway cache is a separate, independent storage layer between the client and the application. It caches the requests made by the client and sends them to the application. Similarly, it sends the responses from the application to the client. If a resource is requested again, the cache returns the response before reaching the application. The gateway cache is shared, but by servers, not users, and includes items such as the endpoint of an API.
This storage is done in the application. It allows the developer to specify which elements the browser should cache and make them available to users even offline. These elements might include local editing capabilities of certain documents (e.g.: Google Docs) or storing data in a temporary database only to have sync to the online one once the device is connected to the internet.
A server cache is similar to a browser cache, only that it keeps data server-side instead of saving it locally. It’s often used to save database queries to avoid running memory and CPU-intensive tasks for the popular queries. Server cached data includes dynamically created web pages, database queries API responses and more.
How Does the Cache Work?
Copies of data are stored in designated locations, either locally or on the server. This saves resources trying to run difficult queries on databases or those loading large images from the server every time a website loads.
Browsers will check these locations before requesting the resource from the server, and if it’s found, it will be loaded from the cache instead of having it downloaded, which would be significantly slower.
Why Is a Cache Important?
A cache is critical as it helps developers improve performance. Here are the main benefits:
A cache is crucial to speed up data retrieval. This helps the website load faster and deliver the content to the users as quickly as possible. Without using a cache, every time a new request is made, the server would have to send over the entire package of data regardless of whether the information in the response has changed or not.
Caches will help you save on data transfers. Applications you use frequently won’t have to download the entire page every time you navigate to a different view, just the changed or new files.
The cache also allows you to use certain apps in “Offline Mode.” A great example of that is Google Docs. While the app does require an internet connection leveraging the local cache in your browser (also called “local storage”), you’ll have the ability to continue working and sync all your local data once your connection is back up.
The cache can be used as a contingency. In some cases, data can get corrupted. If you have a cached version of the app or website, you can use it as a backup.
Disadvantages of Caches
Storage demands. Anything you cache either locally or on the server will take a lot of space. While this can cause a machine to slow down to a halt, fixing it is rather simple since most caches have a “clear cache” option that will wipe it clean and free up all that space.
A corrupt version of the cache can break an app. While your cache can be used as a backup, it can easily backfire by making the application rely on corrupted data, making the information completely useless, or even worse, having the website throw an error. To be able to use the app again, you have to clear the cache manually.
Solely relying on the cache can cause a version mismatch between the client and the server. While in theory there are contingencies in place to avoid this, this error can occur, especially when you use a hybrid app that can work both offline and online.
What Does It Mean to Clear Cache?
Cached data can sometimes take up a lot of space on your machine. If it has no expiration date or it’s not set up to be cleared automatically, you’ll have to do it yourself. This usually means navigating to the location where cached data is stored and deleting it.
Another reason why you should need to clear your cache is if you suspect having a corrupted version of the app cached. In this case, the easiest fix would be to clear the cache and get a whole new version stored on your machine.
Keep in mind that each time you clear your cache, you’ll have to spend resources to download another copy of the website or app data which can be time-consuming.
How to Clear Cached Data
There are various ways to clear cached data depending on its type.
You can clear web browser cache files by going to the Settings menu in your browser and clicking the “Clear browser data” button.
Clearing data on a server can be significantly more difficult since there’s usually no settings tab. It would have to be done by accessing the root folder and navigating to wherever the chase is stored to delete it manually. Luckily more often than not, developers will set up automated tasks to clear out the cache after a certain period.
What Happens After You Clear the Cache?
After the cache is cleared, every new request will download another copy of the data from the server, or, in the case of databases, they will run new queries. Once the data is ready, it will be sent back to the client in the request message.
Cache Monitoring with Sematext
To make sure your cache is not affecting your website performance, you should keep an eye on how users utilize cached resources. A good monitoring tool will provide insight into how efficient your caching system is, if it’s overutilized or underutilized and if you should consider implementing a different way to store temporary data.
Sematext has two options for keeping an eye on your cache – Synthetics, a synthetic monitoring tool, and Experience, a real user monitoring solution. Both will provide a lot of detail on the average time the browser has spent retrieving cached resources as well as other key website performance metrics like TTFB, FCP, LCS, and more.