Skip to content

Commit

Permalink
fix memcached on ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Feb 12, 2024
1 parent a97ed11 commit a0d9b85
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def self.deprecated_url(var)
when "memory"
config.cache_store = :memory_store # to debug cache keys, bundle open activesupport -> active_support/cache.rb#log
when "memcached"
require_relative "initializers/sockify"
options = {
value_max_bytes: 3000000,
compress: true,
Expand Down
15 changes: 15 additions & 0 deletions config/initializers/sockify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TODO: remove one `rails runner 'Rails.cache.fetch 1'` works with memcached
# dalli has this code inside an `if RUBY_VERSION >= '3.0'` but only old version works
require 'dalli'

class Dalli::Socket::TCP
def self.open(host, port, options = {})
Timeout.timeout(options[:socket_timeout]) do
sock = new(host, port)
sock.options = { host: host, port: port }.merge(options)
init_socket_options(sock, options)

options[:ssl_context] ? wrapping_ssl_socket(sock, host, options[:ssl_context]) : sock
end
end
end

0 comments on commit a0d9b85

Please sign in to comment.