A platform for community discussion. Free, open, simple.
FIX: Invalidate stylesheet cache when discourse-fonts is bumped (#30869)
David Taylor23edfe7cc27c
diff --git a/lib/stylesheet/manager.rb b/lib/stylesheet/manager.rbindex 1ab10790269..ce66bd44d38 100644--- a/lib/stylesheet/manager.rb+++ b/lib/stylesheet/manager.rb@@ -7,8 +7,12 @@ module Stylesheetendclass Stylesheet::Manager+ # Bump this number to invalidate all stylesheet caches (e.g. if you change something inside the compiler)BASE_COMPILER_VERSION = 2+ # Add any dependencies here which should automatically cause a global cache invalidation.+ BASE_CACHE_KEY = "#{BASE_COMPILER_VERSION}::#{DiscourseFonts::VERSION}"+CACHE_PATH = "tmp/stylesheet-cache"private_constant :CACHE_PATH@@ -132,13 +136,13 @@ class Stylesheet::Managerif File.exist?(manifest_full_path)File.readlines(manifest_full_path, "r")[0]else- cachebuster = "#{BASE_COMPILER_VERSION}:#{fs_assets_hash}"+ cachebuster = "#{BASE_CACHE_KEY}:#{fs_assets_hash}"FileUtils.mkdir_p(MANIFEST_DIR)File.open(manifest_full_path, "w") { |f| f.print(cachebuster) }cachebusterendelse- "#{BASE_COMPILER_VERSION}:#{max_file_mtime}"+ "#{BASE_CACHE_KEY}:#{max_file_mtime}"endenddiff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rbindex ccb66085aee..32d87fb4063 100644--- a/spec/lib/stylesheet/manager_spec.rb+++ b/spec/lib/stylesheet/manager_spec.rb@@ -1043,7 +1043,7 @@ RSpec.describe Stylesheet::Manager dodescribe ".fs_asset_cachebuster" doit "returns a number in test/development mode" do- expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A[0-9]+:[0-9]+\z/)+ expect(Stylesheet::Manager.fs_asset_cachebuster).to match(/\A.*:[0-9]+\z/)endcontext "with production mode enabled" do@@ -1056,7 +1056,7 @@ RSpec.describe Stylesheet::Manager doit "returns a hash" docachebuster = Stylesheet::Manager.fs_asset_cachebuster- expect(cachebuster).to match(/\A[0-9]+:[0-9a-f]{40}\z/)+ expect(cachebuster).to match(/\A.*:[0-9a-f]{40}\z/)endit "caches the value on the filesystem" do