cache item show pages as a first try :)

This commit is contained in:
Emi Matchu 2010-12-08 20:15:46 -05:00
parent b7fb5a952b
commit ca9e1fb0ca
10 changed files with 52 additions and 3 deletions

View file

@ -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 'em-http-request',:git => 'git://github.com/igrigorik/em-http-request.git', :require => 'em-http'
gem 'thin', '~> 1.2.7' gem 'thin', '~> 1.2.7'
gem 'memcache-client', '~> 1.8.5', :require => ['memcache', 'memcache/event_machine']
end end
group :test do group :test do

View file

@ -91,6 +91,7 @@ GEM
i18n (>= 0.4.1) i18n (>= 0.4.1)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
memcache-client (1.8.5)
mime-types (1.16) mime-types (1.16)
msgpack (0.4.3) msgpack (0.4.3)
openneo-auth-signatory (0.1.0) openneo-auth-signatory (0.1.0)
@ -163,6 +164,7 @@ DEPENDENCIES
haml (~> 3.0.18) haml (~> 3.0.18)
hoptoad_notifier hoptoad_notifier
jammit (~> 0.5.3) jammit (~> 0.5.3)
memcache-client (~> 1.8.5)
msgpack (~> 0.4.3) msgpack (~> 0.4.3)
mysqlplus! mysqlplus!
openneo-auth-signatory (~> 0.1.0) openneo-auth-signatory (~> 0.1.0)

View file

@ -1,5 +1,6 @@
class ItemsController < ApplicationController class ItemsController < ApplicationController
before_filter :set_query before_filter :set_query
caches_action :show, :layout => false
def index def index
if params.has_key?(:q) if params.has_key?(:q)

View file

@ -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

View file

@ -1,3 +1,5 @@
# requires item sweeper at bottom
class Item < ActiveRecord::Base class Item < ActiveRecord::Base
SwfAssetType = 'object' SwfAssetType = 'object'
@ -705,3 +707,5 @@ class Item < ActiveRecord::Base
class SearchError < ArgumentError;end class SearchError < ArgumentError;end
end end
require 'item_sweeper'

View file

@ -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

View file

@ -20,7 +20,7 @@ module OpenneoImpressItems
# config.plugins = [ :exception_notification, :ssl_requirement, :all ] # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running # 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. # 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. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.

View file

@ -12,7 +12,7 @@ OpenneoImpressItems::Application.configure do
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_view.debug_rjs = 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 # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
@ -20,4 +20,6 @@ OpenneoImpressItems::Application.configure do
config.active_support.deprecation = :log config.active_support.deprecation = :log
end end
LocalImpressHost = 'betanewimpress.openneo.net'
RemoteImpressHost = 'beta.impress.openneo.net' RemoteImpressHost = 'beta.impress.openneo.net'

View file

@ -25,7 +25,7 @@ OpenneoImpressItems::Application.configure do
# config.logger = SyslogLogger.new # config.logger = SyslogLogger.new
# Use a different cache store in production # 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 # Disable Rails's static asset server
# In production, Apache or nginx will already do this # In production, Apache or nginx will already do this
@ -43,6 +43,8 @@ OpenneoImpressItems::Application.configure do
config.active_support.deprecation = :log config.active_support.deprecation = :log
end end
LocalImpressHost = 'newimpress.openneo.net'
RemoteImpressHost = 'impress.openneo.net' RemoteImpressHost = 'impress.openneo.net'
USE_FIBER_POOL = true USE_FIBER_POOL = true

BIN
vendor/cache/memcache-client-1.8.5.gem vendored Normal file

Binary file not shown.