Module: Chefdepartie::Cache
Instance Method Summary collapse
Instance Method Details
#cache(path) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chefdepartie/cache.rb', line 19 def cache(path) return false unless cache? hash = File.file?(path) ? CityHash.hash128(File.read(path)) : hashdir(path) hit = @cache[to_key(path)] == hash hit = false unless File.exists?(File.join(@storage, to_key(path))) unless hit @cache[to_key(path)] = hash dump end hit end |
#cache? ⇒ Boolean
31 32 33 |
# File 'lib/chefdepartie/cache.rb', line 31 def cache? !@cache.nil? end |
#flush ⇒ Object
35 36 37 38 |
# File 'lib/chefdepartie/cache.rb', line 35 def flush @cache = {} dump end |
#setup(path) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/chefdepartie/cache.rb', line 10 def setup(path) @storage = File.join(path, 'organizations', 'chef') @path = File.join(path, 'cache.dat') FileUtils.mkdir_p(@storage) if File.exist?(@path) then restore else @cache = {} end ds = ChefZero::DataStore::RawFileStore.new(File.join(path)) ChefZero::DataStore::DefaultFacade.new(ds, false, false) end |