Closed vitalinfo closed 4 years ago
@vitalinfo how did you solve your issue?
Same problem here.
@huacnlee is it possible to change the caching place? Or to disable it ?
Monkey Patch
module RailsSettings
class RequestCache
class << self
def reset
Rails.cache.write('foo', nil)
end
def settings
Rails.cache.read('foo')
end
def settings=(val)
Rails.cache.write('foo', val)
end
end
end
end
My workaround is that RequestStore
exist only inside a single web-request/job/task. So on every request Rails reads Rails.cache
for values and stores it to global variable within request, what RequestStore
is.
This situation happened for me because I was trying to check if my var is updated on different instances with rails console
, but for this case console-session it is the single "request". To ensure that everything is working as suggested, I add debug-loggers into the different places of code and run this on instances. That confirms variables are changed as expected. The only issue when it can fail - some kind of long request with many Setting
-readings when all queries are served by RequestCache.
Hi, all
I just create a Issue https://github.com/huacnlee/rails-settings-cached/issues/219
I will try to fix this problem.
My workaround is that
RequestStore
exist only inside a single web-request/job/task. So on every request Rails readsRails.cache
for values and stores it to global variable within request, whatRequestStore
is. This situation happened for me because I was trying to check if my var is updated on different instances withrails console
, but for this case console-session it is the single "request". To ensure that everything is working as suggested, I add debug-loggers into the different places of code and run this on instances. That confirms variables are changed as expected. The only issue when it can fail - some kind of long request with manySetting
-readings when all queries are served by RequestCache.
RequestCache it avoid Redis I/O, when on page have multiple setting keys wants to read.
For now, you can call RailsSettings::RequestCache.reset
directly to clean RequestCache
@huacnlee what was the case to use that in real environment?
version 2.8.0 fixed this.
@rhombl4 sorry for the later answer, I've resolved it with https://github.com/madebylotus/request_store-sidekiq but looks like it isn't actual anymore
@vitalinfo For now, you not need it.
I have a few web-servers and a few sidekiq worksers and use Redis store as a primary cache. If update any setting from the one web-server application, it doesn't update on another instances, because of
RequestStore
local cache. Doesn't it make any sense to useRequestStore
? Why just not useRails.cache
as a one source of thrust?