# File lib/geminabox/disk_cache.rb, line 21 def cache(key) key_hash = key_hash(key) read(key_hash) || write(key_hash, yield) end
# File lib/geminabox/disk_cache.rb, line 16 def flush FileUtils.rm_rf(root_path) ensure_dir_exists! end
# File lib/geminabox/disk_cache.rb, line 33 def ensure_dir_exists! FileUtils.mkdir_p(root_path) end
# File lib/geminabox/disk_cache.rb, line 37 def key_hash(key) Digest::MD5.hexdigest(key) end
# File lib/geminabox/disk_cache.rb, line 49 def marshal_read(key_hash) read_int(key_hash) { |path| Marshal.load(File.open(path)) } end
# File lib/geminabox/disk_cache.rb, line 63 def marshal_write(key_hash, value) write_int(key_hash) { |f| Marshal.dump(value, f) } value end
# File lib/geminabox/disk_cache.rb, line 41 def path(key_hash) File.join(root_path, key_hash) end
# File lib/geminabox/disk_cache.rb, line 45 def read(key_hash) read_int(key_hash) { |path| File.read(path) } end
# File lib/geminabox/disk_cache.rb, line 53 def read_int(key_hash) path = path(key_hash) yield(path) if File.exists?(path) end
Generated with the Darkfish Rdoc Generator 2.