Caching Paths



Caching paths is the main function of bootsnap. Previously, I mentioned that Bootsnap creates 2 caches:

  • Stable: For Gems and Rubies since these are highly unlikely to change
  • Volatile: For everything else, like your app code, since this is likely to change

This path is shown in the flowchart below. In a number of instances, scan is mentioned. This refers to the operation performed by the Path Scanner.

diagram image

Mtimes (modified times) of files and directories

We do not take mtimes into account for stable caches. This is a more expensive operation so we avoid it when we can (this avoids as many filesystem calls as we can).

  • This means for a “stable” cache, we simply use 0 as the mtime for all files, so there is no effect on the cache heuristic.
  • For a “volatile” cache however, we find the maximum mtime of all files and directories in the given path. This means that if any file within a directory is added or removed, the cache is invalidated.
    • Note, the mtime is initialized at -1, so if the path doesn’t exist, -1 will be returned.