Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (23 sloc) 428 Bytes
class MyCacheStore
attr_accessor :store_hash
def initialize
@store_hash = {}
end
def write(key, value)
@store_hash[key.to_sym] = value
end
def read(key)
@store_hash[key.to_sym]
end
def fetch(key)
raise('Block should be provided') unless block_given?
result = read(key)
if result.nil?
result = yield
write(key, result)
result
else
result
end
end
end