diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index ae96d65574..a3a288f620 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -588,8 +588,7 @@ module Cask def self.find_cask_in_tap(token, tap) filename = "#{token}.rb" - Tap.cask_files_by_name(tap) - .fetch(token, tap.cask_dir/filename) + tap.cask_files_by_name.fetch(token, tap.cask_dir/filename) end end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 1900976a27..0d59ec16e3 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -129,6 +129,7 @@ class Tap @formula_names = nil @formula_files = nil @cask_files = nil + @cask_files_by_name = nil @alias_dir = nil @alias_files = nil @aliases = nil @@ -590,19 +591,12 @@ class Tap end end - # A cached hash of {Cask} basenames to {Cask} file pathnames for a {Tap} - sig { params(tap: Tap).returns(T::Hash[String, Pathname]) } - def self.cask_files_by_name(tap) - cache_key = "cask_files_by_name_#{tap}" - cache.fetch(cache_key) do |key| - cache[key] = tap.cask_files_by_name - end - end - + # A mapping of {Cask} tokens to {Cask} file paths. + # # @private sig { returns(T::Hash[String, Pathname]) } def cask_files_by_name - cask_files.each_with_object({}) do |file, hash| + @cask_files_by_name ||= cask_files.each_with_object({}) do |file, hash| # If there's more than one file with the same basename: use the longer one to prioritise more specific results. basename = file.basename(".rb").to_s existing_file = hash[basename]