From: Tom Hughes Date: Sun, 22 Sep 2013 14:57:22 +0000 (+0100) Subject: Drop memcached and use dalli as the memcache client X-Git-Tag: live~5322 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/255b0b94252b48a9fe4326bb9d9fc4f184308460 Drop memcached and use dalli as the memcache client --- diff --git a/Gemfile b/Gemfile index 11587ec3f..f8fa61130 100644 --- a/Gemfile +++ b/Gemfile @@ -77,8 +77,9 @@ gem 'SystemTimer', '>= 1.1.3', :require => 'system_timer', :platforms => :ruby_1 # Load httpclient for SOAP support for Quova GeoIP queries gem 'httpclient' -# Load memcache in case we are using it -gem 'memcached', '>= 1.4.1' +# Load memcache client in case we are using it +gem 'dalli' +gem 'kgio' # Gems useful for development group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 46d3e98ac..aeaa596e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,6 +45,7 @@ GEM coffee-script-source (1.6.3) composite_primary_keys (6.0.0) activerecord (>= 4.0.0) + dalli (2.6.4) deadlock_retry (1.2.0) dynamic_form (1.1.4) ejs (1.1.1) @@ -70,11 +71,11 @@ GEM jsonify (< 0.4.0) jwt (0.1.8) multi_json (>= 1.5) + kgio (2.8.1) libxml-ruby (2.7.0) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - memcached (1.7.0) mime-types (1.25) mini_portile (0.5.1) minitest (4.7.5) @@ -176,6 +177,7 @@ DEPENDENCIES bigdecimal (~> 1.1.0) coffee-rails (~> 4.0.0) composite_primary_keys (>= 6.0.0) + dalli deadlock_retry (>= 1.2.0) dynamic_form ejs @@ -186,8 +188,8 @@ DEPENDENCIES jquery-rails json jsonify-rails + kgio libxml-ruby (>= 2.0.5) - memcached (>= 1.4.1) minitest (~> 4.7.0) open_id_authentication (>= 1.1.0) openstreetmap-i18n-js (>= 3.0.0.rc5.2) diff --git a/config/environments/production.rb b/config/environments/production.rb index 35222bd07..b47013a8a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -58,7 +58,7 @@ OpenStreetMap::Application.configure do # Use a different cache store in production. if defined?(MEMCACHE_SERVERS) - config.cache_store = :mem_cache_store, MemCache.new(:namespace => "rails:cache", :no_block => true, :buffer_requests => true, :noreply => true) + config.cache_store = :mem_cache_store, MEMCACHE_SERVERS, { :namespace => "rails:cache" } end # Enable serving of images, stylesheets, and JavaScripts from an asset server. diff --git a/config/initializers/openid.rb b/config/initializers/openid.rb index a171d1e7b..2a6de16b2 100644 --- a/config/initializers/openid.rb +++ b/config/initializers/openid.rb @@ -1,7 +1,7 @@ if defined?(MEMCACHE_SERVERS) require "openid/store/memcache" - OpenIdAuthentication.store = OpenID::Store::Memcache.new(MemCache.new(:namespace => "rails", :string_return_types => true)) + OpenIdAuthentication.store = OpenID::Store::Memcache.new(Dalli::Client.new(MEMCACHE_SERVERS, :namespace => "rails")) else OpenIdAuthentication.store = :file end diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index aa9071404..1430b0016 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,9 +1,7 @@ # Be sure to restart your server when you modify this file. if defined?(MEMCACHE_SERVERS) - cache = MemCache.new(:namespace => "rails:session", :string_return_types => true) - - OpenStreetMap::Application.config.session_store :mem_cache_store, :cache => cache, :key => "_osm_session" + OpenStreetMap::Application.config.session_store :mem_cache_store, :memcache_servers => MEMCACHE_SERVERS, :namespace => "rails:session", :key => "_osm_session" else OpenStreetMap::Application.config.session_store :cache_store, :key => '_osm_session' end diff --git a/lib/mem_cache.rb b/lib/mem_cache.rb deleted file mode 100644 index ddb842b53..000000000 --- a/lib/mem_cache.rb +++ /dev/null @@ -1,31 +0,0 @@ -class MemCache < Memcached::Rails - DEFAULT_OPTIONS = Memcached::DEFAULTS.merge(Memcached::Rails::DEFAULTS) - - MemCacheError = Memcached::Error - - @@connections = [] - - def initialize(options = {}) - options.reverse_merge! :namespace_separator => ":" - - super(MEMCACHE_SERVERS, options) - - @@connections.push(self) - - ObjectSpace.define_finalizer(self, lambda { |connection| - @@connections.remove(connection) - }) - end - - def self.connections - @@connections - end -end - -if defined?(PhusionPassenger) - PhusionPassenger.on_event(:starting_worker_process) do |forked| - if forked - MemCache.connections.each { |connection| connection.reset } - end - end -end diff --git a/lib/memcache.rb b/lib/memcache.rb deleted file mode 100644 index e69de29bb..000000000