Module: Bootsnap::LoadPathCache

Defined in:
lib/bootsnap/load_path_cache.rb,
lib/bootsnap/load_path_cache/path.rb,
lib/bootsnap/load_path_cache/cache.rb,
lib/bootsnap/load_path_cache/store.rb,
lib/bootsnap/load_path_cache/path_scanner.rb,
lib/bootsnap/load_path_cache/change_observer.rb,
lib/bootsnap/load_path_cache/loaded_features_index.rb

Defined Under Namespace

Modules: ChangeObserver, PathScanner Classes: Cache, LoadedFeaturesIndex, Path, Store

Constant Summary collapse

FALLBACK_SCAN =
BasicObject.new
DOT_RB =
".rb"
DOT_SO =
".so"
SLASH =
"/"
DL_EXTENSIONS =
::RbConfig::CONFIG
.values_at("DLEXT", "DLEXT2")
.reject { |ext| !ext || ext.empty? }
.map    { |ext| ".#{ext}" }
.freeze
DLEXT =
DL_EXTENSIONS[0]
DLEXT2 =

This is nil on linux and darwin, but I think it’s ‘.o’ on some other platform. I’m not really sure which, but it seems better to replicate ruby’s semantics as faithfully as possible.

DL_EXTENSIONS[1]
CACHED_EXTENSIONS =
DLEXT2 ? [DOT_RB, DLEXT, DLEXT2] : [DOT_RB, DLEXT]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject (readonly) Also known as: enabled?

Returns the value of attribute enabled.



27
28
29
# File 'lib/bootsnap/load_path_cache.rb', line 27

def enabled
  @enabled
end

.load_path_cacheObject (readonly)

Returns the value of attribute load_path_cache.



27
28
29
# File 'lib/bootsnap/load_path_cache.rb', line 27

def load_path_cache
  @load_path_cache
end

.loaded_features_indexObject (readonly)

Returns the value of attribute loaded_features_index.



27
28
29
# File 'lib/bootsnap/load_path_cache.rb', line 27

def loaded_features_index
  @loaded_features_index
end

Class Method Details

.setup(cache_path:, development_mode:, ignore_directories:, readonly: false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bootsnap/load_path_cache.rb', line 31

def setup(cache_path:, development_mode:, ignore_directories:, readonly: false)
  unless supported?
    warn("[bootsnap/setup] Load path caching is not supported on this implementation of Ruby") if $VERBOSE
    return
  end

  store = Store.new(cache_path, readonly: readonly)

  @loaded_features_index = LoadedFeaturesIndex.new

  PathScanner.ignored_directories = ignore_directories if ignore_directories
  @load_path_cache = Cache.new(store, $LOAD_PATH, development_mode: development_mode)
  @enabled = true
  require_relative "load_path_cache/core_ext/kernel_require"
  require_relative "load_path_cache/core_ext/loaded_features"
end

.supported?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bootsnap/load_path_cache.rb', line 56

def supported?
  if RUBY_PLATFORM.match?(/darwin|linux|bsd|mswin|mingw|cygwin/)
    case RUBY_ENGINE
    when "truffleruby"
      # https://github.com/oracle/truffleruby/issues/3131
      RUBY_ENGINE_VERSION >= "23.1.0"
    when "ruby"
      true
    else
      false
    end
  end
end

.unload!Object



48
49
50
51
52
53
54
# File 'lib/bootsnap/load_path_cache.rb', line 48

def unload!
  @enabled = false
  @loaded_features_index = nil
  @realpath_cache = nil
  @load_path_cache = nil
  ChangeObserver.unregister($LOAD_PATH) if supported?
end