class Poto::Services::FileCache
Attributes
path[R]
Public Class Methods
new(path:)
click to toggle source
# File lib/poto/services/file_cache.rb, line 8 def initialize(path:) @path = path end
Public Instance Methods
cache(key) { || ... }
click to toggle source
# File lib/poto/services/file_cache.rb, line 12 def cache(key) File.join(path, filename(key)).tap do |cache_path| unless File.exist?(cache_path) file_path = yield FileUtils.cp(file_path, cache_path) end end end
Private Instance Methods
filename(key)
click to toggle source
# File lib/poto/services/file_cache.rb, line 23 def filename(key) Digest::SHA256.hexdigest(key) end