Module: Inq::Cacheable::MarshalCache
- Defined in:
- lib/inq/cacheable.rb
Overview
This is only okay on a local system
Class Method Summary collapse
-
.cached(key, tmpdir) ⇒ Object
rubocop:disable Security/MarshalLoad.
Class Method Details
.cached(key, tmpdir) ⇒ Object
rubocop:disable Security/MarshalLoad
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/inq/cacheable.rb', line 47 def cached(key, tmpdir) require "fileutils" path = File.join(tmpdir, "inq", key) FileUtils.mkdir_p(File.dirname(path)) ret = nil if File.exist?(path) File.open(path, "rb") do |f| ret = Marshal.load(f) end ret else ret = yield File.open(path, "wb") do |file| Marshal.dump(ret, file) end end ret end |