PERF: Defer setting of distributed cache in performance critical paths.

Setting a key/value pair in DistributedCache involves waiting on the
write to Redis to finish. In most cases, we don't need to wait on the
setting of the cache to finish. We just need to take our return value
and move on.
This commit is contained in:
Alan Guo Xiang Tan
2021-06-02 15:46:48 +08:00
parent 83211cff25
commit 8cfe203383
5 changed files with 25 additions and 9 deletions

View File

@ -11,4 +11,12 @@ class DistributedCache < MessageBus::DistributedCache
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
end