Class: Bootscale::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/bootscale/cache.rb

Direct Known Subclasses

ActiveSupport::Cache, DevelopmentCache

Instance Method Summary collapse

Constructor Details

#initialize(cache_directory = nil) ⇒ Cache

Returns a new instance of Cache.



5
6
7
8
# File 'lib/bootscale/cache.rb', line 5

def initialize(cache_directory = nil)
  @storage = FileStorage.new(cache_directory) if cache_directory
  reload
end

Instance Method Details

#[](path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/bootscale/cache.rb', line 18

def [](path)
  path = path.to_s
  return if path.start_with?(LEADING_SLASH)
  reload(false)
  if path.end_with?(DOT_RB, DOT_SO)
    @cache[path]
  else
    @cache["#{path}#{DOT_RB}"] || @cache["#{path}#{DOT_SO}"]
  end
end

#load_pathObject



10
11
12
# File 'lib/bootscale/cache.rb', line 10

def load_path
  $LOAD_PATH
end

#reload(force = true) ⇒ Object



14
15
16
# File 'lib/bootscale/cache.rb', line 14

def reload(force = true)
  @cache = fetch(load_path) if force
end