FIX: Cache keys should be strings (#25791)

* FIX: Cache keys should be strings

Otherwise, there are subtle bugs that don't show up with a single
process.
This commit is contained in:
Daniel Waterworth 2024-02-21 10:55:48 -06:00 committed by GitHub
parent 428db40deb
commit 13291dc5ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -936,7 +936,7 @@ class Category < ActiveRecord::Base
end
def url
@@url_cache.defer_get_set(self.id) do
@@url_cache.defer_get_set(self.id.to_s) do
"#{Discourse.base_path}/c/#{slug_path.join("/")}/#{self.id}"
end
end

View File

@ -14,6 +14,8 @@ class DistributedCache < MessageBus::DistributedCache
end
def defer_get_set(k, &block)
raise TypeError if !Rails.env.production? && !k.is_a?(String)
return self[k] if hash.key? k
value = block.call
self.defer_set(k, value)