LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

tmpfs ~/.cache cleaner daemon-script idea, to clean RAM space while trying to minimize SSD writes

Posted 10-27-2020 at 07:20 AM by the dsc
Updated 11-01-2020 at 03:45 AM by the dsc (maybe grammar or worse, maybe style)
Tags hack, script, ssd, tmpfs

In line with the idea of reducing how much it's written on SSD, some people suggest using tmpfs for lots of things, one of them can be the ~/.cache directory. Which must be implemented in a per-user basis or with some pre-mount script that would do such tmpfs mounts before each user login. But regardless, the point is that they may spare the SSD, but not the RAM, obviously. If you quit a cache-heavy program, its cache would still be there, leaving other programs you're running with less RAM to use. Possibly even then forcing the OS to write things to the swap partition (if that's not completely disabled, which some people do), which would then be a counterproductive scenario in more than one aspect.

It seems that a reasonable solution could be some script-daemon that periodically checks whether the main programs are running and removes their subdirectories at ~/.cache, when those exist. Somewhat like this:

Code:
#!/bin/bash

while true ; do

if ! pgrep someprogram ; then

[[ -e ~/.cache/someprogramscachedirwithadifferentname ]] && rm -rf ~/.cache/someprogramscachedirwithadifferentname

fi

sleep 5m

done
For programs that more fortunately use the process name for its cache subdirectory, then it perhaps could be done in a secondary/internal loop like:

Code:
for program in processA processB processC processD ; do

if ! pgrep ${program} ; then

[[ -e ~/.cache/${program} ]] && rm -rf ~/.cache/${program}

fi

done
Posted in Uncategorized
Views 201 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 12:17 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration