Skip to content

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.rb
index 1ab10790269..ce66bd44d38 100644
--- a/lib/stylesheet/manager.rb
+++ b/lib/stylesheet/manager.rb
@@ -7,8 +7,12 @@ module Stylesheet
end
class 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::Manager
if 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) }
cachebuster
end
else
- "#{BASE_COMPILER_VERSION}:#{max_file_mtime}"
+ "#{BASE_CACHE_KEY}:#{max_file_mtime}"
end
end
diff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rb
index 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 do
describe ".fs_asset_cachebuster" do
it "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/)
end
context "with production mode enabled" do
@@ -1056,7 +1056,7 @@ RSpec.describe Stylesheet::Manager do
it "returns a hash" do
cachebuster = 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/)
end
it "caches the value on the filesystem" do