class Fontist::Utils::Cache
Constants
- MAX_FILENAME_SIZE
Public Class Methods
lock_path(path)
click to toggle source
# File lib/fontist/utils/cache.rb, line 8 def self.lock_path(path) "#{path}.lock" end
Public Instance Methods
already_fetched?(keys)
click to toggle source
# File lib/fontist/utils/cache.rb, line 26 def already_fetched?(keys) map = load_cache keys.find { |k| cache_exist?(map[k]) } end
delete(key)
click to toggle source
# File lib/fontist/utils/cache.rb, line 31 def delete(key) lock(lock_path) do map = load_cache return unless map[key] value = map.delete(key) File.write(cache_map_path, YAML.dump(map)) value end end
fetch(key) { || ... }
click to toggle source
# File lib/fontist/utils/cache.rb, line 12 def fetch(key) map = load_cache if Fontist.use_cache? && cache_exist?(map[key]) print(map[key]) return downloaded_file(map[key]) end generated_file = yield path = save_cache(generated_file, key) downloaded_file(path) end
set(key, value)
click to toggle source
# File lib/fontist/utils/cache.rb, line 42 def set(key, value) lock(lock_path) do map = load_cache map[key] = value File.write(cache_map_path, YAML.dump(map)) end end