forked from OpenNeo/impress
cache item show pages as a first try :)
This commit is contained in:
parent
b7fb5a952b
commit
ca9e1fb0ca
10 changed files with 52 additions and 3 deletions
2
Gemfile
2
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class ItemsController < ApplicationController
|
||||
before_filter :set_query
|
||||
caches_action :show, :layout => false
|
||||
|
||||
def index
|
||||
if params.has_key?(:q)
|
||||
|
|
8
app/controllers/sweeper_controller.rb
Normal file
8
app/controllers/sweeper_controller.rb
Normal 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
|
|
@ -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'
|
||||
|
|
28
app/models/item_sweeper.rb
Normal file
28
app/models/item_sweeper.rb
Normal 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
|
|
@ -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.
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
vendor/cache/memcache-client-1.8.5.gem
vendored
Normal file
BIN
vendor/cache/memcache-client-1.8.5.gem
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue