Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache doesn't clean for distributed system #182

Closed
vitalinfo opened this issue Apr 1, 2020 · 10 comments
Closed

Cache doesn't clean for distributed system #182

vitalinfo opened this issue Apr 1, 2020 · 10 comments

Comments

@vitalinfo
Copy link

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 use RequestStore? Why just not use Rails.cache as a one source of thrust?

@rhombl4
Copy link

rhombl4 commented Aug 25, 2021

@vitalinfo how did you solve your issue?

@Piioo
Copy link

Piioo commented Sep 13, 2021

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

@rhombl4
Copy link

rhombl4 commented Sep 13, 2021

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.

@huacnlee
Copy link
Owner

Hi, all

I just create a Issue #219

I will try to fix this problem.

@huacnlee
Copy link
Owner

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.

RequestCache it avoid Redis I/O, when on page have multiple setting keys wants to read.

@huacnlee
Copy link
Owner

For now, you can call RailsSettings::RequestCache.reset directly to clean RequestCache

@rhombl4
Copy link

rhombl4 commented Sep 14, 2021

@huacnlee what was the case to use that in real environment?

@huacnlee
Copy link
Owner

version 2.8.0 fixed this.

@vitalinfo
Copy link
Author

@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

@huacnlee
Copy link
Owner

@vitalinfo For now, you not need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants