Module: HeapInfo::Cache::ClassMethods

Included in:
HeapInfo::Cache
Defined in:
lib/heapinfo/cache.rb

Overview

Define class methods.

Instance Method Summary collapse

Instance Method Details

#clear_allvoid

This method returns an undefined value.

Clear the cache directory.


47
48
49
# File 'lib/heapinfo/cache.rb', line 47

def clear_all
  FileUtils.rm_rf(CACHE_DIR)
end

#key_libc_offset(libc_path) ⇒ String

Get the key for store libc offsets.


17
18
19
# File 'lib/heapinfo/cache.rb', line 17

def key_libc_offset(libc_path)
  File.join('libc', Digest::MD5.hexdigest(IO.binread(libc_path)), 'offset')
end

#read(key) ⇒ Object?

Read cache from file.


37
38
39
40
41
42
43
# File 'lib/heapinfo/cache.rb', line 37

def read(key)
  filepath = realpath(key)
  return unless File.file?(filepath)
  Marshal.load(IO.binread(filepath))
rescue TypeError, ArgumentError
  nil # handle if file content is invalid
end

#write(key, value) ⇒ Boolean

Write cache to file.


26
27
28
29
30
31
# File 'lib/heapinfo/cache.rb', line 26

def write(key, value)
  filepath = realpath(key)
  FileUtils.mkdir_p(File.dirname(filepath))
  IO.binwrite(filepath, Marshal.dump(value))
  true
end