class Ec2Meta::Cache
Public Class Methods
new()
click to toggle source
# File lib/ec2_meta/cache.rb, line 5 def initialize @cache = {} end
Public Instance Methods
clear()
click to toggle source
# File lib/ec2_meta/cache.rb, line 34 def clear @cache.clear end
delete(key)
click to toggle source
# File lib/ec2_meta/cache.rb, line 30 def delete(key) @cache.delete(key) end
exist?(key)
click to toggle source
# File lib/ec2_meta/cache.rb, line 26 def exist?(key) @cache.key?(key.to_s) end
fetch(key) { || ... }
click to toggle source
# File lib/ec2_meta/cache.rb, line 17 def fetch(key) return read(key) if exist?(key) raise ArgumentError, 'require block' unless block_given? value = yield write(key, value) end
read(key)
click to toggle source
# File lib/ec2_meta/cache.rb, line 13 def read(key) @cache[key.to_s] end
write(key, value)
click to toggle source
# File lib/ec2_meta/cache.rb, line 9 def write(key, value) @cache[key.to_s] = value end