sorentwo / readthis

:newspaper: Pooled active support compliant caching with redis
MIT License
506 stars 40 forks source link

Set readthis connection pool after configuring cache_store as readthis_store? #54

Closed bcavileer closed 7 years ago

bcavileer commented 7 years ago

If I configure this in my config/production.rb

  config.cache_store = :readthis_store, {
      expires_in: 30.seconds.to_i,
      namespace: 'cache',
      redis: { url: ENV.fetch('REDIS_URL'), driver: :hiredis }
  }

How can I set it's connection pool later when my puma workers call on_worker_boot

on_worker_boot is called after config/production.rb

The pool for readthis cannot be passed in via options

https://github.com/sorentwo/readthis/blob/master/lib/readthis/cache.rb#L59

I am stuck. Before I start hacking and making a mess I thought I'd ask here if I'm on the right track?

https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot

https://devcenter.heroku.com/articles/concurrency-and-database-connections#threaded-servers

bcavileer commented 7 years ago

I was thinking of a change like this https://github.com/holmansv/readthis/commit/2698143da9620e6c1c0a9884dd8f332649703052

But I'm not sure how ReadThis gets initialized when set as Rails cache_store, and how to set this after bootup?

sorentwo commented 7 years ago

The pool's connections are established lazily and will be automatically reconnected after forking.

I've written a bit about how it is undesirable to explicitly re-establish the pool after forking: http://sorentwo.com/2015/08/25/managing-redis-reconnections-from-ruby.html

So, good news, you don't need to do anything =)

bcavileer commented 7 years ago

Thank you!!

On Mon, Jul 3, 2017, 12:36 PM Parker Selbert notifications@github.com wrote:

The pool's connections are established lazily https://github.com/mperham/connection_pool/blob/master/lib/connection_pool/timed_stack.rb#L12 and will be automatically reconnected after forking.

I've written a bit about how it is undesirable to explicitly re-establish the pool after forking: http://sorentwo.com/2015/08/25/managing-redis-reconnections-from-ruby.html

So, good news, you don't need to do anything =)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sorentwo/readthis/issues/54#issuecomment-312690053, or mute the thread https://github.com/notifications/unsubscribe-auth/AAF5BvT92op_4yxbU8pvFCFMt85SvGDTks5sKRh6gaJpZM4OLWTa .