Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Cache on startup #85

Open
boredsquirrel opened this issue Mar 16, 2023 · 5 comments
Open

Clean Cache on startup #85

boredsquirrel opened this issue Mar 16, 2023 · 5 comments
Labels
contributors welcome good first issue Good for newcomers priority prioritized soft mod just simple tweaks software related software stuffs system wide modification program option that will modify a system wide setting user wide modification program option that will modify a user wide setting
Milestone

Comments

@boredsquirrel
Copy link
Collaborator

boredsquirrel commented Mar 16, 2023

Some user meant this was a problem. It can not harm to delete old cache from various flatpaks. The command for that is:

find ~/.var/app/*/cache/ -type f -mtime +7 -delete
touch ~/.cache-cleaner.log

printf """#!/bin/bash
sleep 30
rm ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -delete
find ~/.cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.cache/ -type f -mtime +7 -delete""" > ~/.config/autostart/cache-cleaner.sh

chmod +x ~/.config/autostart/cache-cleaner.sh
@boredsquirrel
Copy link
Collaborator Author

more complex version running the script on reboot, shutdown or logout:

mkdir -p ~/.config/systemd/user
mkdir ~/.config/autostop

# create unit

printf """[Unit]
Description=Execute scripts located at ~/.config/autostop on logout, shutdown or reboot

[Service]
Type=oneshot
ExecStart=/bin/true
#ExecStop=/usr/bin/find ~/.config/autostop/ -type f -name '*.sh' -exec /bin/bash {} \;
ExecStop=/bin/bash -c 'for file in ~/.config/autostop/*; do [[ -x "$file" ]] && "$file"; done'

[Install]
WantedBy=default.target""" > ~/.config/systemd/user/autostop.service

# enable
systemctl --user daemon-reload

systemctl --user enable autostop.service

The first version executes all found "*.sh" scripts.

The second version checks if files are executeable and executes them in that case. Both versions are pretty neat.

It seems systemd has a feature to check if it stops and execute a command in that case.

To use the cache-cleaner, just put it in that directory.

@boredsquirrel
Copy link
Collaborator Author

boredsquirrel commented Mar 16, 2023

So here is the version using the autostop feature

touch ~/.cache-cleaner.log

printf """#!/bin/bash
rm ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.var/app/*/cache/ -type f -mtime +7 -delete
find ~/.cache/ -type f -mtime +7 -print | tee >> ~/.cache-cleaner.log
find ~/.cache/ -type f -mtime +7 -delete""" > ~/.config/autostop/cache-cleaner.sh

chmod +x ~/.config/autostop/cache-cleaner.sh

@boredsquirrel
Copy link
Collaborator Author

disable logging:

sed '/cache-cleaner/d' ~/.config/autostart/cache-cleaner.sh
sed '/cache-cleaner/d' ~/.config/autostop/cache-cleaner.sh
rm ~/.cache-cleaner.log

@iaacornus
Copy link
Collaborator

this is a good idea. from what i heard, apple has this sort of stuff. it would be better if we can just integrate this as background process after boot, rather than on shut down, since long shut down time can be irritating

@iaacornus iaacornus added good first issue Good for newcomers priority prioritized system wide modification program option that will modify a system wide setting user wide modification program option that will modify a user wide setting software related software stuffs soft mod just simple tweaks contributors welcome labels Apr 2, 2023
@iaacornus iaacornus added this to the 0.1-alpha milestone Apr 2, 2023
@boredsquirrel
Copy link
Collaborator Author

This is very personal. For me I dont care if boot takes long, but I want the laptop to be there when I turn it on. So I would say end is way better.

I mean using the nice autostop service (I think I tried it, I dont know) you can just ask the user where to put it, and then put it there.

Also such a cache cleaner is not official. There is /tmp which is cleaned, there is ~/.cache with is cleaned, and the Flatpak apps themselves should manage their cache well. But I guess they dont, so no way will I not integrate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributors welcome good first issue Good for newcomers priority prioritized soft mod just simple tweaks software related software stuffs system wide modification program option that will modify a system wide setting user wide modification program option that will modify a user wide setting
Projects
None yet
Development

No branches or pull requests

2 participants