Can the Rails Tmp/Cache/Assets Files Be Safely Deleted

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

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

files in /tmp/cache/ of a new rails application (258 directories, 1404 files)

Short answer: You are safe to delete the /tmp/cache/bootsnap-compile-cache.

Long answer: Bootsnap, as I'm sure you're aware, is a Ruby library that optimizes and caches expensive computations, meaning you can boot Ruby/Rails applications faster.

One of the strategies Bootsnap employs to speed up your application is known as Compilation Caching.

Ruby has to translate ruby source into internal bytecode, which the VM then executes. What Bootsnap does is cleverly cache a bunch of these translations in cache files that consist of headers and cache contents (these are the files stored under the directory in question). This is done so that when your application performs its various operations, it can simply to do a lookup on the already-translated bytecode cached by Bootsnap, instead of performing the relatively-expensive compilation step, thus making the code execute faster.

A readable implementation of this concept can be found here

As you might have guessed by now, deleting those files will simply mean your application runs a little slower locally, until the operations are subsequently cached once more.

Unfortunately, to the best of my knowledge, there is currently no automatic purging mechanism for Bootsnap's cache. The library leaves cleaning up the cache up to the user (a la assets:clean or container pruning).

Hope that helps!

Clear the cache from the Rails asset pipeline

I'm assuming we're talking about the production environment.

When you change any of your javascripts or stylesheets in the production environment, you need to run rake assets:precompile; this task compiles and compresses the various .js and .css files and creates the application.js and application.css files that is loaded by your views.

It's possible that if you replaced jquery.autoresize.js with a version with an older timestamp, the precompile step might skip it, thinking the compiled version is up-to-date. You can avoid that by running rake assets:clean first, forcing it to rebuild everything in the public/assets directory from scratch.

Rake assets:clobber and precompile causes git merge conflicts

Compiled assets aren't something you would normally want to have in your git repository. I would just add an entry for /public/assets to a .gitignore file in the root directory of your application.

Since you've already committed the compiled assets, you will want to remove them from the repo:

git rm --cached -r /public/assets


Related Topics



Leave a reply



Submit