Easily Free Up Linux System Cache In Memory
Here’s a tip for webmasters and blog owners that will show you how to easily free up systems’ caches in memory using Linux. This usually will come in handy if you’re want immediate results after making changes to your website’s codes.
For example, if you run a WordPress blog with W3 Total Cache installed and functioning great. All your web’s content are being cached and served to clients via W3TC. You made some changes to your website codes and after emptying W3 Total Cache’s folder, the changes are still be being applied to your site. Your webserver is still serving cached content. In order to immediately empty all cached content in the system’s memory, you may want to run these commands below.
First, check to see if you have cached content in memory. To do that, run the commands below.
After running the above command, you’ll see information about your system’s memory (free / used) and cached content.
Before running the command, check to see the current value for Linux kernel drop_caches. It should be 0. Run the commands below to check.
Now, to immediately free up all cached content, including dentries, inodes run the commands below.
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
The above commands changes the value to 3 from 0.
After the cached content are removed, change it back to 0 by running the commands below.
sudo sh -c "sync; echo 0 > /proc/sys/vm/drop_caches"
With other Linux systems like CentOS or openSUSE, you may want to run this as root.
sh -c "sync; echo 0 > /proc/sys/vm/drop_caches"
Now check again.