Class: Chef::ChefFS::FileSystemCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/chef/chef_fs/file_system_cache.rb

Instance Method Summary collapse

Constructor Details

#initializeFileSystemCache

Returns a new instance of FileSystemCache


26
27
28
29
30
31
32
# File 'lib/chef/chef_fs/file_system_cache.rb', line 26

def initialize
  @cache = {}

  Chef::Client.when_run_starts do
    FileSystemCache.instance.reset!
  end
end

Instance Method Details

#children(path) ⇒ Object


42
43
44
# File 'lib/chef/chef_fs/file_system_cache.rb', line 42

def children(path)
  @cache[path]["children"]
end

#delete!(path) ⇒ Object


52
53
54
55
56
57
58
59
60
61
# File 'lib/chef/chef_fs/file_system_cache.rb', line 52

def delete!(path)
  parent = _get_parent(path)
  Chef::Log.debug("Deleting parent #{parent} and #{path} from FileSystemCache")
  if @cache.key?(path)
    @cache.delete(path)
  end
  if !parent.nil? && @cache.key?(parent)
    @cache.delete(parent)
  end
end

#exist?(path) ⇒ Boolean

Returns:

  • (Boolean)

38
39
40
# File 'lib/chef/chef_fs/file_system_cache.rb', line 38

def exist?(path)
  @cache.key?(path)
end

#fetch(path) ⇒ Object


63
64
65
66
67
68
69
# File 'lib/chef/chef_fs/file_system_cache.rb', line 63

def fetch(path)
  if @cache.key?(path)
    @cache[path]
  else
    false
  end
end

#reset!Object


34
35
36
# File 'lib/chef/chef_fs/file_system_cache.rb', line 34

def reset!
  @cache = {}
end

#set_children(path, val) ⇒ Object


46
47
48
49
50
# File 'lib/chef/chef_fs/file_system_cache.rb', line 46

def set_children(path, val)
  @cache[path] ||= { "children" => [] }
  @cache[path]["children"] = val
  val
end