Module: HeapInfo::Cache::ClassMethods
- Included in:
- HeapInfo::Cache
- Defined in:
- lib/heapinfo/cache.rb
Overview
Define class methods.
Instance Method Summary collapse
-
#clear_all ⇒ void
Clear the cache directory.
-
#key_libc_info(libc_path) ⇒ String
Get the key for storing libc info.
-
#read(key) ⇒ Object?
Read cache from file.
-
#write(key, value) ⇒ Boolean
Write cache to file.
Instance Method Details
#clear_all ⇒ void
This method returns an undefined value.
Clear the cache directory.
49 50 51 |
# File 'lib/heapinfo/cache.rb', line 49 def clear_all FileUtils.rm_rf(CACHE_DIR) end |
#key_libc_info(libc_path) ⇒ String
Get the key for storing libc info.
19 20 21 |
# File 'lib/heapinfo/cache.rb', line 19 def key_libc_info(libc_path) File.join('libc', Digest::MD5.hexdigest(IO.binread(libc_path)), 'info') end |
#read(key) ⇒ Object?
Read cache from file.
39 40 41 42 43 44 45 |
# File 'lib/heapinfo/cache.rb', line 39 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.
28 29 30 31 32 33 |
# File 'lib/heapinfo/cache.rb', line 28 def write(key, value) filepath = realpath(key) FileUtils.mkdir_p(File.dirname(filepath)) IO.binwrite(filepath, Marshal.dump(value)) true end |