lib/nutrella/cache.rb in nutrella-1.5.4 vs lib/nutrella/cache.rb in nutrella-1.6.0
- old
+ new
@@ -18,10 +18,16 @@
value = lookup(key) || yield
write(key, value)
value
end
+ def search(search_reg_exp)
+ cache_contents.find { |k, _v| search_reg_exp.match?(k) }.last
+ rescue
+ nil
+ end
+
private
def lookup(key)
cache_contents.find { |k, _v| k == key }.last
rescue
@@ -39,9 +45,13 @@
rescue
[[key, value]]
end
def cache_contents
- @_cache_contents ||= YAML.load_file(path)
+ @_cache_contents ||= begin
+ YAML.load_file(path)
+ rescue
+ nil
+ end
end
end
end