diff --git a/Library/Homebrew/test/api/cask_spec.rb b/Library/Homebrew/test/api/cask_spec.rb index a3d787993c400..932897dbe810f 100644 --- a/Library/Homebrew/test/api/cask_spec.rb +++ b/Library/Homebrew/test/api/cask_spec.rb @@ -7,8 +7,6 @@ before do stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) - Homebrew::API.clear_cache - described_class.clear_cache end def mock_curl_download(stdout:) diff --git a/Library/Homebrew/test/api/formula_spec.rb b/Library/Homebrew/test/api/formula_spec.rb index 49a3101064d7e..8b89d1916b99d 100644 --- a/Library/Homebrew/test/api/formula_spec.rb +++ b/Library/Homebrew/test/api/formula_spec.rb @@ -7,7 +7,6 @@ before do stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) - described_class.clear_cache end def mock_curl_download(stdout:) diff --git a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb index cc03354e23885..a6347e1806cfb 100644 --- a/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb +++ b/Library/Homebrew/test/api/internal_tap_json/formula_spec.rb @@ -44,12 +44,6 @@ # To allow `formula_names.txt` to be written to the cache. (HOMEBREW_CACHE/"api").mkdir - - Homebrew::API::Formula.clear_cache - end - - after do - Homebrew::API::Formula.clear_cache end it "loads tap aliases" do diff --git a/Library/Homebrew/test/api_spec.rb b/Library/Homebrew/test/api_spec.rb index 585c91f0eecd8..9186fc625cb94 100644 --- a/Library/Homebrew/test/api_spec.rb +++ b/Library/Homebrew/test/api_spec.rb @@ -8,10 +8,6 @@ let(:json_hash) { JSON.parse(json) } let(:json_invalid) { '{"foo":"bar"' } - before do - described_class.clear_cache - end - def mock_curl_output(stdout: "", success: true) curl_output = instance_double(SystemCommand::Result, stdout:, success?: success) allow(Utils::Curl).to receive(:curl_output).and_return curl_output diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 3bb7491bdf0c5..6b53acf40c6e7 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -81,8 +81,6 @@ def install end context "with sharded Formula directory" do - before { CoreTap.instance.clear_cache } - let(:formula_name) { "testball_sharded" } let(:formula_path) do core_tap = CoreTap.instance @@ -236,7 +234,6 @@ class Wrong#{described_class.class_s(formula_name)} < Formula before do alias_dir.mkpath FileUtils.ln_s formula_path, alias_path - tap.clear_cache end it "returns a Formula when given a name" do diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index baaebc895bf05..5caaf2fa704f3 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -4,10 +4,6 @@ require "formula_installer" RSpec.describe Utils::Analytics do - before do - described_class.clear_cache - end - describe "::default_package_tags" do let(:ci) { ", CI" if ENV["CI"] } diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index c09fd7f2fe444..51bdebaa455f9 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -16,6 +16,8 @@ module Analytics INFLUX_HOST = "https://eu-central-1-1.aws.cloud2.influxdata.com" INFLUX_ORG = "d81a3e6d582d485f" + extend Cachable + class << self include Context @@ -277,14 +279,9 @@ def cask_output(cask, args:) nil end - def clear_cache - remove_instance_variable(:@default_package_tags) if instance_variable_defined?(:@default_package_tags) - remove_instance_variable(:@default_package_fields) if instance_variable_defined?(:@default_package_fields) - end - sig { returns(T::Hash[Symbol, String]) } def default_package_tags - @default_package_tags ||= begin + cache[:default_package_tags] ||= begin # Only display default prefixes to reduce cardinality and improve privacy prefix = Homebrew.default_prefix? ? HOMEBREW_PREFIX.to_s : "custom-prefix" @@ -305,7 +302,7 @@ def default_package_tags # remove macOS patch release sig { returns(T::Hash[Symbol, String]) } def default_package_fields - @default_package_fields ||= begin + cache[:default_package_fields] ||= begin version = if (match_data = HOMEBREW_VERSION.match(/^[\d.]+/)) suffix = "-dev" if HOMEBREW_VERSION.include?("-") match_data[0] + suffix.to_s