diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index f2dceb7fad..acfc04ada7 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -9,6 +9,11 @@ require "utils/json" # `Tab.create`. class Tab < OpenStruct FILENAME = "INSTALL_RECEIPT.json" + CACHE = {} + + def self.clear_cache + CACHE.clear + end def self.create(formula, compiler, stdlib, build) attributes = { @@ -32,7 +37,7 @@ class Tab < OpenStruct end def self.from_file(path) - from_file_content(File.read(path), path) + CACHE.fetch(path) { |p| CACHE[p] = from_file_content(File.read(p), p) } end def self.from_file_content(content, path) @@ -217,6 +222,7 @@ class Tab < OpenStruct end def write + CACHE[tabfile] = self tabfile.atomic_write(to_json) end diff --git a/Library/Homebrew/test/test_formula_installer.rb b/Library/Homebrew/test/test_formula_installer.rb index 63bba3f87a..643712d0cb 100644 --- a/Library/Homebrew/test/test_formula_installer.rb +++ b/Library/Homebrew/test/test_formula_installer.rb @@ -20,10 +20,12 @@ class InstallTests < Homebrew::TestCase assert_predicate formula, :installed? begin + Tab.clear_cache refute_predicate Tab.for_keg(keg), :poured_from_bottle yield formula ensure + Tab.clear_cache keg.unlink keg.uninstall formula.clear_cache