One of the easiest ways to speed up a slow website is to make use of a web cache. Caching involves the temporary storage of a part of a website or media on that site. There are several ways to implement caching in order to improve site speed and performance. MintTwist, provides a service that makes use of several caching options in order to bolster speed and performance of all live sites.
Table of Contents
What is a DNS cache?
A DNS (domain name system) cache is a small, temporary database on your computer that stores a record of all the recent websites that you have visited over the internet. When you visit a website, your computer makes a request to your internet service provider, which routes that request through to a DNS provider. This provider then finds and returns back to your computer the IP address for the site you are looking for. Your browser then sends a HTTP request to that IP address which then returns the website to be displayed in your web browser.
By storing a list of recent sites that you have visited on your machine, a DNS cache means that your computer doesn’t always have to make that initial request to find the IP address of a domain name, as it is saved in memory still. While most people use Windows, each operating system stores and manages its DNS cache in a slightly different way. The exception being for Linux based systems, which don’t use a DNS cache at all by default.
To view your DNS cache on a Windows machine and see what sites you have saved, first open the command prompt (windows + R, then type run ‘cmd’). Enter the command ‘ipconfig /displaydns’ and press return. This shows you a long list of domain names (Record Name) and the subsequent saved DNS information (A (Host) Record or CNAME Record) that is recorded locally on your machine.
How to clear your DNS cache
Windows: From the command prompt, enter ‘ipconfig /flushdns’ and press return. If you then view the cache via ‘ipconfig /displayns’ then you will see that it has been wiped clean.
Mac: For all recent versions of OSX (Catalina, Mojave, High Sierra, Sierra and El Capitan), run the command ‘sudo killall -HUP mDNSResponder’ in the terminal. For some older versions, you will need to run ‘sudo discoveryutil udnsflushcaches’ instead.
Linux: As Linux has no DNS cache enabled by default, clearing the cache is based on the optional service that you have enabled. For nscd, run ‘sudo /etc/init.d/nscd restart’ and for dnsmasq, run ‘sudo /etc/init.d/dnsmasq restart’.
Google Chrome: Chrome also keeps its own DNS cache. This can be cleared by visiting ‘chrome://net-internals/#dns’ and clicking on the ‘Clear host cache’ button.
Routers: Some routers, depending on make and model might also be saving their own DNS cache. The simplest way to reset this is to restart your router.
Why are caches used?
Caches can be used in a variety of ways, but the aim each time is to ultimately speed up the loading experience for when visiting a website. The faster a website loads, the higher it also ranks when people search for its subject in Google. DNS caches speed up initial steps required to load a web page. This method skips the need for a DNS lookup. Other caches can save loading times for websites on computers or mobile devices by saving copies of images and media on your computer, web servers or networks.
Disadvantages of caching
The disadvantage of using a cache can be that a large amount of disk space is taken up as more and more videos and images are downloaded so that they don’t have to be retrieved again each time. Depending on the aggressiveness of the caching, you might also not always be seeing the latest images or versions of some sites. Finding the right time for your cache to expire and renew along with regularly clearing it out can mitigate these potential issues.
Some websites will communicate back to your computer to tell them that some parts of a site or a page have changed, and that the cache should be abandoned and new material re-downloaded. Although this isn’t always utilised, this allows website developers to make use of caching while forcing updates when necessary.
Growing need for caching
The increase in the use of mobile internet browsing has given rise to a greater need for caching and speed as people come to rely more on cellular networks than traditional private ones. Some solutions, like Google’s AMP (Accelerated Mobile Pages), aim to, among other things, solve some of the issues that might otherwise be solved or improved by taking advantage of a traditional cache by copying existing sites and serving them at greater speed.
Other types of cache
There are many ways in which a website can cache its content; each with its own uses, advantages and pitfalls. If you are seeing an older version of a site, missing the latest updates or just looking to implement a cache for your website, then there are several options to take into account.
There are client-side web caches which run locally on each site visitor’s computer. A site cache is controlled by the user from their computer, as are most forms of DNS caching and browser caching, which like the name suggests is managed and retained by the web browser itself.
Server-side caches run on the web server and are controlled only by the website administrator and cannot be affected by visitors to the site. Server caches take several forms:
Object cache:
This stores the results of queries that run against the sites database so that they can be retrieved quickly without the need to run resource intensive requests each time a request is made.
OpCode cache:
PHP is a type of code that runs on a server and is compiled into bytecode, running each time a user visits a page. OpCache cache is a system that caches the PHP after it is compiled into bytecode so that it doesn’t need to be recompiled each time it runs.
CDN cache:
A content delivery network is a network of servers in different locations that host websites nearby their users so that they can access the site faster. This network caches content for faster delivery.