mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:19:27 +08:00
a8667b5454
See follow up commit for rational.
Follow-up to 8cfe203383
30 lines
703 B
Ruby
30 lines
703 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'message_bus/distributed_cache'
|
|
|
|
class DistributedCache < MessageBus::DistributedCache
|
|
def initialize(key, manager: nil, namespace: true)
|
|
super(
|
|
key,
|
|
manager: manager,
|
|
namespace: namespace,
|
|
app_version: Discourse.git_version
|
|
)
|
|
end
|
|
|
|
# Defer setting of the key in the cache for performance critical path to avoid
|
|
# waiting on MessageBus to publish the message which involves writing to Redis.
|
|
def defer_set(k, v)
|
|
Scheduler::Defer.later("#{@key}_set") do
|
|
self[k] = v
|
|
end
|
|
end
|
|
|
|
def defer_get_set(k, &block)
|
|
return self[k] if self[k]
|
|
value = block.call
|
|
self.defer_set(k, value)
|
|
value
|
|
end
|
|
end
|