It is always mandatory to create a backup before making any changes to any server. If you do not have a backup: Purchase the IONOS Cloud Backup, follow the installation instructions, and complete a manual backup (video).
Cache is a temporary storage of data that helps improve the performance and efficiency of your system. However, sometimes cache can become outdated, corrupted, or take up too much space. In this tutorial, you will learn how to clear cache on Linux and Windows servers using various methods and tools.
Prerequisites
To follow this tutorial, you will need:
- Access to a Linux server or a Windows server
- Basic knowledge of Linux or Windows commands
- Administrator privileges on the server
Clearing WordPress Site’s Cache
WordPress site’s cache is a collection of files that store the content and layout of your website. It helps reduce the loading time and bandwidth usage of your site. However, sometimes you may need to clear the cache to see the latest changes or fix some issues. To clear the cache, you can use one of the following methods:
- If you are using a caching plugin, such as WP Super Cache or W3 Total Cache, you can clear the cache from the plugin’s settings page. For example, for WP Super Cache, go to Settings > WP Super Cache > Delete Cache. If you are using WP Rocket, you can go to Settings → WP Rocket and click on the Clear Cache button at the top. If you are using W3 Total Cache, you can go to Performance → Dashboard and click on the Empty All Caches button.
- If you are using a CDN service, such as Cloudflare or Sucuri, you can clear the cache from the CDN’s dashboard. For example, for Cloudflare, go to Caching > Configuration > Purge Cache.
- If you want to clear the cache manually, you can delete the cache files from your server. For example, for WP Super Cache, go to wp-content > cache > supercache and delete the files and folders inside.
WP-CLI is a command-line tool that allows you to manage your WordPress site on a Linux server from the terminal. If you have SSH access to your WordPress server, you can use WP-CLI to clear WordPress cache with a simple command.
To clear WordPress cache with WP-CLI, you need to connect to your server via SSH and navigate to your WordPress root directory. Then, you can use the following command to clear the cache:
wp cache flush
This command will clear the WordPress Object Cache, which stores transient data and database queries. By default, the WP Object Cache exists in PHP memory for the length of the request and is emptied at the end.
Clearing RAM Memory Cache, Buffer and Swap Space on Linux
RAM memory cache, buffer, and swap space are different types of cache that store data in the main memory of your Linux server. They should not be manually cleared on a production server for general maintenance. To clear them anyway, you can use the following commands:
- To clear the page cache, run
sudo sync; sudo echo 1 > /proc/sys/vm/drop_caches
- To clear the dentries and inodes cache, run
sudo sync; sudo echo 2 > /proc/sys/vm/drop_caches
- To clear both the page cache, and the dentries and inodes cache, run
sudo sync; sudo echo 3 > /proc/sys/vm/drop_caches
- To clear the swap space, run
sudo swapoff -a; sudo swapon -a
You can use the free -h
command to check the memory usage before and after clearing the cache.
Clearing DNS Server Cache on Windows Server
DNS server cache is a record of the domain names and IP addresses that your Windows server has resolved. It helps speed up the DNS resolution process and reduce the network traffic. However, sometimes you may need to clear the cache to refresh the DNS records or troubleshoot some problems. To clear the cache, you can use one of the following methods:
- To clear the cache from the DNS Manager console, open the DNS Manager, right-click on your server name, and select Clear Cache.
- To clear the cache from the command prompt, run
dnscmd /clearcache
- To clear the cache from the PowerShell, run
Clear-DnsServerCache
Clearing Update Cache on Windows Server
Update cache is a folder that stores the downloaded updates and update revisions for your Windows server. It helps ensure the integrity and availability of the updates. However, sometimes you may need to clear the cache to free up disk space or fix some errors. To clear the cache, you can use one of the following methods:
- To clear the cache from the Server Cleanup Wizard, open the Server Manager, go to Roles > Windows Server Update Services > Update Services, right-click on your server name, and select Server Cleanup Wizard. Check the boxes for the items you want to delete, such as Unused updates and update revisions, and click Next.
Clearing Disk Cache on Windows Server
Disk cache is a portion of the hard disk that stores frequently accessed data. It helps improve the read and write speed of your Windows server. However, sometimes you may need to clear the cache to optimize the disk performance or troubleshoot some issues. To clear the cache, you can use the Disk Cleanup tool. To use the tool, follow these steps:
- Open the File Explorer, right-click on the drive you want to clean, and select Properties.
- Click on the Disk Cleanup button.
- Check the boxes for the items you want to delete, such as Temporary files, Recycle Bin, and Thumbnails, and click OK.
- Click on the Clean up system files button to delete more items, such as Windows Update Cleanup, Previous Windows installations, and Windows upgrade log files, and click OK.
Conclusion
In this tutorial, you learned how to clear cache on Linux and Windows servers using various methods and tools. Clearing cache can help you improve the performance, efficiency, and security of your servers. However, you should also be careful not to clear the cache on production servers unless absolutely necessary. Also, clearing cache too often or too aggressively may affect the functionality or stability of your server. You should always backup your data before clearing the cache, and test the results after clearing the cache.