{"id":160,"date":"2017-06-30T15:43:59","date_gmt":"2017-06-30T15:43:59","guid":{"rendered":"https:\/\/newdelhihosting.co.in\/blog\/?p=160"},"modified":"2024-10-22T10:46:27","modified_gmt":"2024-10-22T10:46:27","slug":"how-to-clear-cache-memory","status":"publish","type":"post","link":"https:\/\/www.newdelhihosting.co.in\/blog\/how-to-clear-cache-memory\/","title":{"rendered":"How to Clear Cache Memory"},"content":{"rendered":"<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Linux has implemented a memory management efficiently.If any process is eating away your memory and you want to clear it.Linux provides a way to flush or clear ram cache.<\/p>\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Every Linux System has three options to clear cache without interrupting or services.<\/p>\n<p><strong>1.Clear PageCache Only.<\/strong><\/p>\n<pre># sync; echo 1 &gt; \/proc\/sys\/vm\/drop_caches<\/pre>\n<p><strong>2.Clear dentries and inodes.<\/strong><\/p>\n<pre># sync; echo 2 &gt; \/proc\/sys\/vm\/drop_caches<\/pre>\n<p><strong>3.Clear Pagecache,dentries and inodes.<\/strong><\/p>\n<pre># sync; echo 3 &gt; \/proc\/sys\/vm\/drop_caches<\/pre>\n<p>Explain above command<\/p>\n<p style=\"text-align: left;\"><strong>\u00a0 \u00a0 \u00a0 \u00a0 Sync<\/strong> will flush the file system buffer.Command Separated by <strong>&#8220;;&#8221;<\/strong> run sequentially.The Shell wait for each command to terminate before executing the next command in the sequence.<strong>drop_cache<\/strong> will clean cache without killing any application\/service.<strong>echo<\/strong> is doing the job of writing to file<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0Now we will create a shell script to auto clear RAM cache daily at 2am via cron scheduler task.Create a shell script clearcache.sh and add the following lines.<\/p>\n<pre>#!\/bin\/bash\r\n# Note, we are using \"echo 3\", but it is not recommended in production instead use \"echo 1\"\r\necho \"echo 3 &gt; \/proc\/sys\/vm\/drop_caches\"<\/pre>\n<p>Set execute permission on the clearcache.sh file.<\/p>\n<pre># chmod 755 clearcache.sh<\/pre>\n<p>Now you may call the script whenever you requires to clear ram cache<br \/>\nNow set a cron to clear RAM cache everyday at 2am.Open crontab for editing<\/p>\n<pre># crontab -e<\/pre>\n<p>Append the bellow line,save and exit to run it at 2am daily<\/p>\n<pre>0  2  *  *  *  \/path\/to\/clearcache.sh<\/pre>\n<p>For more details on <a href=\"https:\/\/newdelhihosting.co.in\/blog\/2017\/06\/30\/how-to-cron-a-job\/\" target=\"_blank\" rel=\"noopener\">How to cron a job<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Linux has implemented a memory management efficiently.If any process is eating away your memory and you want to clear it.Linux provides a way to flush or clear ram cache. \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Every Linux System has three options to clear cache without interrupting or services. 1.Clear&#8230;<\/p>\n","protected":false},"author":1,"featured_media":428,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[12],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"jetpack_featured_media_url":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-content\/uploads\/2017\/06\/clear.jpg","_links":{"self":[{"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/posts\/160"}],"collection":[{"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":9,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions\/192"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/media\/428"}],"wp:attachment":[{"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.newdelhihosting.co.in\/blog\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}