Home > Dịch vụ VPS > Hệ điều hành Centos > [How To] Clear cache memory & set cronjob on Linux

[How To] Clear cache memory & set cronjob on Linux

The cache memory in Linux systems is used to speed up the response. To learn more about cache, clickhere to visit the website.

Hopefully, after referring to the website the concept about cache in Linux should get clear.

If you still wish to free up the cache memory here you go.

To clear cache memory using command as user root:

1
sync; echo 3 > /proc/sys/vm/drop_caches

 To set cronjob to clear cache memory at specific intervals:

  • Access server through shell as a root user.
  • Create a shell script say "clearcache.sh" under root partition and enter following contents
1
2
#!/bin/sh
sync; echo 3 > /proc/sys/vm/drop_caches
  • Now, set the permission of script " /root/clearcache.sh" to 755
1
chmod 755 /root/clearcache.sh
  • Now edit crontab file
1
crontab -e
  • Enter following line to set cronjob for clearing cache every hour
1
0 * * * * /root/clearcache.sh
  • Restart crond service
1
/etc/init.d/crond restart