Class: Fontist::Utils::Cache
- Inherits:
-
Object
- Object
- Fontist::Utils::Cache
- Includes:
- Locking
- Defined in:
- lib/fontist/utils/cache.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Locking
Class Method Details
.lock_path(path) ⇒ Object
6 7 8 |
# File 'lib/fontist/utils/cache.rb', line 6 def self.lock_path(path) "#{path}.lock" end |
Instance Method Details
#delete(key) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fontist/utils/cache.rb', line 24 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) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fontist/utils/cache.rb', line 10 def fetch(key) map = load_cache if 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) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/fontist/utils/cache.rb', line 35 def set(key, value) lock(lock_path) do map = load_cache map[key] = value File.write(cache_map_path, YAML.dump(map)) end end |