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

What is the correct way to configure memcached? #450

Closed
mmalek-sa opened this issue Apr 6, 2020 · 3 comments
Closed

What is the correct way to configure memcached? #450

mmalek-sa opened this issue Apr 6, 2020 · 3 comments

Comments

@mmalek-sa
Copy link

Configuration in readme file is really confusing and doesn't work for me:

config.identity_cache_store = :memcached_store, Memcached::Rails.new(
      servers: memcached_hosts,
      support_cas: true,
      auto_eject_hosts: false,  # avoids more cache consistency issues
      expires_in: 6.hours.to_i, # in case of network errors when sending a delete
    )

Returns this error:

.rvm/gems/ruby-2.5.7/gems/memcached-1.8.0/lib/memcached/memcached.rb:115:in `block in initialize': :expires_in is not a valid configuration parameter. (ArgumentError)

Looking at the source code of memcached, correct parameter is default_ttl, using this config:

config.identity_cache_store = :memcached_store, Memcached::Rails.new(
      servers: memcached_hosts,
      support_cas: true,
      auto_eject_hosts: false,  # avoids more cache consistency issues
      default_ttl: 6.hours.to_i, # in case of network errors when sending a delete
    )

then gives this error:

.rvm/gems/ruby-2.5.7/gems/memcached_store-2.1.4/lib/active_support/cache/memcached_store.rb:71:in `initialize': Memcached::Rails is no longer supported, use a Memcached instance instead (RuntimeError)

On some other issues #211 and the source code of IdentityCache itself in test/helpers/cache_connection.rb I saw that ActiveSupport::Cache::MemcachedStore.new is used:

config.identity_cache_store = :memcached_store, ActiveSupport::Cache::MemcachedStore.new(
      "127.0.0.1:11211",
      support_cas: true,
      auto_eject_hosts: false,  # avoids more cache consistency issues
      default_ttl: 6.hours.to_i, # in case of network errors when sending a delete
    )

throws this error: (using servers: ["127.0.0.1:11211"] doesn't work either)

.rvm/gems/ruby-2.5.7/gems/memcached-1.8.0/lib/memcached/memcached.rb:209:in `block in set_servers': Servers must be either in the format 'host:port[:weight]' (e.g., 'localhost:11211' or  'localhost:11211:10') for a network server, or a valid path to a Unix domain socket (e.g., /var/run/memcached). (ArgumentError)

This config works for me, note that using servers: named parameter also doesn't work:

config.identity_cache_store = :memcached_store, 
      Memcached.new(
        memcached_hosts, # ["127.0.0.1:11211"]
        support_cas: true,
        auto_eject_hosts: false,  # avoids more cache consistency issues
        default_ttl: 6.hours.to_i, # in case of network errors when sending a delete
      )

Is this correct and Readme file outdated or am I missing something here?

I'm using identity_cache 1.0.1 with Rails 6.0.2.2.

@mmalek-sa
Copy link
Author

Just found this PR: #353

Any particular reason why it's not merged?

@dylanahsmith
Copy link
Contributor

Sorry about that. Merged #353

@mmalek-sa
Copy link
Author

Thank you.

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

2 participants