]> git.openstreetmap.org Git - rails.git/commitdiff
Add memcache support
authorTom Hughes <tom@compton.nu>
Sun, 17 Apr 2011 17:56:50 +0000 (18:56 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 17 Apr 2011 17:56:50 +0000 (18:56 +0100)
config/environment.rb
config/environments/production.rb
config/initializers/memcached.rb [new file with mode: 0644]

index e897f3e4ab86efb96b0484764a358b00d9628260..ce5a89350dae69af277772029dbc2c1f3ebcdbd5 100644 (file)
@@ -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
index 5e549a91f73f920b43bffb544fae3a84f0af92f4..457966091416284b01c5f530bee50d30444002f4 100644 (file)
@@ -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 (file)
index 0000000..03066a8
--- /dev/null
@@ -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