class MasterLeague::Cache
Public Class Methods
new(path: '~/.config/master_league_cache.yml')
click to toggle source
# File lib/master_league/cache.rb, line 6 def initialize(path: '~/.config/master_league_cache.yml') path = Pathname.new(path).expand_path if path.file? || path.parent.directory? @store = YAML::Store.new(path) else raise "#{path} is not a valid path for the Cache" end end
Public Instance Methods
clear()
click to toggle source
# File lib/master_league/cache.rb, line 46 def clear @store.transaction do @store.path.delete end end
delete(key)
click to toggle source
# File lib/master_league/cache.rb, line 40 def delete(key) @store.transaction do @store.delete(key) end end
fetch(key) { || ... }
click to toggle source
# File lib/master_league/cache.rb, line 28 def fetch(key, &block) @store.transaction do value = @store[key] if value value else @store[key] = yield end end end
read(key)
click to toggle source
# File lib/master_league/cache.rb, line 22 def read(key) @store.transaction do @store[key] end end
write(key, value)
click to toggle source
# File lib/master_league/cache.rb, line 16 def write(key, value) @store.transaction do @store[key] = value end end