diff --git a/Gemfile b/Gemfile index 676890ef..21d847a2 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ group :development_async, :production do gem 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http' gem 'thin', '~> 1.2.7' + + gem 'memcache-client', '~> 1.8.5', :require => ['memcache', 'memcache/event_machine'] end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 156dbb18..819b2aa0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -91,6 +91,7 @@ GEM i18n (>= 0.4.1) mime-types (~> 1.16) treetop (~> 1.4.8) + memcache-client (1.8.5) mime-types (1.16) msgpack (0.4.3) openneo-auth-signatory (0.1.0) @@ -163,6 +164,7 @@ DEPENDENCIES haml (~> 3.0.18) hoptoad_notifier jammit (~> 0.5.3) + memcache-client (~> 1.8.5) msgpack (~> 0.4.3) mysqlplus! openneo-auth-signatory (~> 0.1.0) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 028448e9..9b26b2e0 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,5 +1,6 @@ class ItemsController < ApplicationController before_filter :set_query + caches_action :show, :layout => false def index if params.has_key?(:q) diff --git a/app/controllers/sweeper_controller.rb b/app/controllers/sweeper_controller.rb new file mode 100644 index 00000000..42e9a157 --- /dev/null +++ b/app/controllers/sweeper_controller.rb @@ -0,0 +1,8 @@ +class SweeperController < ActionController::Base + def expire_action_proxy(options) + options[:only_path] = true + path = Rails.application.routes.url_helpers.url_for(options) + fragment_name = "#{LocalImpressHost}#{path}" + expire_fragment(fragment_name) + end +end diff --git a/app/models/item.rb b/app/models/item.rb index 5c978b3c..249b5030 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -1,3 +1,5 @@ +# requires item sweeper at bottom + class Item < ActiveRecord::Base SwfAssetType = 'object' @@ -705,3 +707,5 @@ class Item < ActiveRecord::Base class SearchError < ArgumentError;end end + +require 'item_sweeper' diff --git a/app/models/item_sweeper.rb b/app/models/item_sweeper.rb new file mode 100644 index 00000000..7e9a8d62 --- /dev/null +++ b/app/models/item_sweeper.rb @@ -0,0 +1,28 @@ +puts 'Hey! Item sweeper!' + +class ItemSweeper < ActionController::Caching::Sweeper + observe Item + + def after_update(item) + expire_cache_for(item) + end + + def after_destroy(item) + expire_cache_for(item) + end + + private + def expire_cache_for(item) + options = {:controller => 'items', :action => 'show', :id => item.id} + expire_action(options) + end + + def expire_action(options) + if @controller + super + elsif LocalImpressHost + @tmp_controller ||= SweeperController.new + @tmp_controller.expire_action_proxy(options.dup) + end + end +end diff --git a/config/application.rb b/config/application.rb index 795a7e99..24ea28c7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,7 +20,7 @@ module OpenneoImpressItems # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer + config.active_record.observers = :item_sweeper # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. diff --git a/config/environments/development.rb b/config/environments/development.rb index 3a320a36..d501eb51 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -12,7 +12,7 @@ OpenneoImpressItems::Application.configure do # Show full error reports and disable caching config.consider_all_requests_local = true config.action_view.debug_rjs = true - config.action_controller.perform_caching = false + config.action_controller.perform_caching = true #false # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false @@ -20,4 +20,6 @@ OpenneoImpressItems::Application.configure do config.active_support.deprecation = :log end +LocalImpressHost = 'betanewimpress.openneo.net' + RemoteImpressHost = 'beta.impress.openneo.net' diff --git a/config/environments/production.rb b/config/environments/production.rb index 4797a853..409fe62a 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -25,7 +25,7 @@ OpenneoImpressItems::Application.configure do # config.logger = SyslogLogger.new # Use a different cache store in production - # config.cache_store = :mem_cache_store + config.cache_store = :mem_cache_store # Disable Rails's static asset server # In production, Apache or nginx will already do this @@ -43,6 +43,8 @@ OpenneoImpressItems::Application.configure do config.active_support.deprecation = :log end +LocalImpressHost = 'newimpress.openneo.net' + RemoteImpressHost = 'impress.openneo.net' USE_FIBER_POOL = true diff --git a/vendor/cache/memcache-client-1.8.5.gem b/vendor/cache/memcache-client-1.8.5.gem new file mode 100644 index 00000000..bbf23945 Binary files /dev/null and b/vendor/cache/memcache-client-1.8.5.gem differ