From: Tom Hughes Date: Sun, 17 Apr 2011 17:56:50 +0000 (+0100) Subject: Add memcache support X-Git-Tag: live~6234^2~44 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/2fd52ddf6024ebdbebf451524836e67f7b4f07a2?ds=sidebyside Add memcache support --- diff --git a/config/environment.rb b/config/environment.rb index e897f3e4a..ce5a89350 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -26,6 +26,9 @@ Rails::Initializer.run do |config| config.gem 'SystemTimer', :version => '>= 1.1.3', :lib => 'system_timer' config.gem 'sanitize' config.gem 'i18n', :version => '>= 0.5.0' + if defined?(MEMCACHE_SERVERS) + config.gem 'memcached' + end # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named diff --git a/config/environments/production.rb b/config/environments/production.rb index 5e549a91f..457966091 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -16,7 +16,10 @@ config.action_view.cache_template_loading = true # config.logger = SyslogLogger.new # Use a different cache store in production -# config.cache_store = :mem_cache_store +if defined?(MEMCACHE_SERVERS) + MEMCACHE = Memcached::Rails.new(MEMCACHE_SERVERS, :binary_protocol => true) + config.cache_store = :mem_cache_store, MEMCACHE +end # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/config/initializers/memcached.rb b/config/initializers/memcached.rb new file mode 100644 index 000000000..03066a8ab --- /dev/null +++ b/config/initializers/memcached.rb @@ -0,0 +1,9 @@ +if defined?(PhusionPassenger) and defined?(MEMCACHE_SERVERS) + PhusionPassenger.on_event(:starting_worker_process) do |forked| + if forked + MEMCACHE = MEMCACHE.clone + RAILS_CACHE = ActiveSupport::Cache::CompressedMemCacheStore.new(MEMCACHE) + ActionController::Base.cache_store = RAILS_CACHE + end + end +end