Can the rails tmp/cache/assets files be safely deleted?
Asked Answered
M

3

30

I seem to have a TON of them in subfolders named for example

sprockets%2F76920e6913c3390459175ac8e6dfd44a3

They seem to contain binary data.

What are they for, why are there so many of them and most importantly, can these be safely removed? They take forever to scp.

Mirabel answered 7/6, 2013 at 16:51 Comment(0)
T
38

Yep! You can delete the whole tmp directory and it will get recreated.

Toxicology answered 7/6, 2013 at 16:54 Comment(2)
Hey do you have some answers to the other parts of the question : what's inside ? Especially, this dir reached > 1GB of disk space on my production instances, can I safely remove it under a production context ? Do I need to execute a rake aseets:compile or something like that afterwardExalted
@CyrilDuchon-Doris These are transitional files (in my case years ago) generated by the sprockets gem as it parses .coffee to .js or .scss to .css - stuff like that. Sometimes they hang out there without getting cleaned up due to things like server crashes or unexpected reloads or not being included in .gitignore.Mirabel
S
4

Yes, you can safely delete it.

The best way to delete will be running the following in the rails console:

Rails.cache.clear
Setzer answered 5/1, 2018 at 16:37 Comment(3)
Thanks. Actually even today I got a problem in my production environments where the disk was full and the server kept throwing 500 errors without any log (even calling a simple du -sh on the tmp dir would freeze for minutes). I think I'm going to add this line to a Capistrano task that I will run every time I release a new app. You think this is ok ?Exalted
Hi @CyrilDuchon-Doris, it can definitely prevent the disk issue - but please be aware that users my experience a bit slower site and will increase access to the DB. You can also use config.action_controller.perform_caching = false. more details here: guides.rubyonrails.org/caching_with_rails.htmlSetzer
That doesn't appear to free up any space in tmp/cache. In particular after running it, tmp/cache/assets/sprockets/v3.0 still has 1,096 subfolders taking up MB on my local machine.Nullify
F
1

There is a rake task for clearing tmp:

rails tmp:clear
Feces answered 3/4, 2020 at 5:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.