Revision: 70391 http://trac.macports.org/changeset/70391 Author: jrozner@macports.org Date: 2010-08-07 22:16:51 -0700 (Sat, 07 Aug 2010) Log Message: ----------- added file based caching Modified Paths: -------------- branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb branches/gsoc10-mpwa/mpwa/config/environment.rb branches/gsoc10-mpwa/mpwa/config/environments/development.rb Added Paths: ----------- branches/gsoc10-mpwa/mpwa/app/sweepers/ branches/gsoc10-mpwa/mpwa/app/sweepers/category_sweeper.rb branches/gsoc10-mpwa/mpwa/app/sweepers/port_sweeper.rb branches/gsoc10-mpwa/mpwa/app/sweepers/ticket_sweeper.rb Modified: branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb 2010-08-08 01:14:34 UTC (rev 70390) +++ branches/gsoc10-mpwa/mpwa/app/controllers/categories_controller.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -1,4 +1,6 @@ class CategoriesController < ApplicationController + caches_page :index + def index @categories = Category.all(:order => 'name ASC') end Modified: branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb 2010-08-08 01:14:34 UTC (rev 70390) +++ branches/gsoc10-mpwa/mpwa/app/controllers/ports_controller.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -1,4 +1,6 @@ class PortsController < ApplicationController + caches_page :index, :show + def index unless params[:category_id].nil? @ports = Category.find(params[:category_id]).ports.paginate :page => params[:page], :order => 'name ASC', :per_page => 50 Added: branches/gsoc10-mpwa/mpwa/app/sweepers/category_sweeper.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/app/sweepers/category_sweeper.rb (rev 0) +++ branches/gsoc10-mpwa/mpwa/app/sweepers/category_sweeper.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -0,0 +1,20 @@ +class CategorySweeper < ActionController::Caching::Sweeper + observe Category + + def after_create(category) + expire_cache_for category + end + + def after_update(category) + expire_cache_for category + end + + def after_destroy(category) + expire_cache_for category + end + +private + def expire_cache_for(category) + expire_page :action => :index + end +end \ No newline at end of file Added: branches/gsoc10-mpwa/mpwa/app/sweepers/port_sweeper.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/app/sweepers/port_sweeper.rb (rev 0) +++ branches/gsoc10-mpwa/mpwa/app/sweepers/port_sweeper.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -0,0 +1,21 @@ +class PortSweeper < ActionController::Caching::Sweeper + observe Port + + def after_create(port) + expire_cache_for port + end + + def after_update(port) + expire_cache_for port + end + + def after_destroy(port) + expire_cache_for port + end + +private + def expire_cache_for(port) + expire_page :action => :index + expire_page :action => :show + end +end \ No newline at end of file Added: branches/gsoc10-mpwa/mpwa/app/sweepers/ticket_sweeper.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/app/sweepers/ticket_sweeper.rb (rev 0) +++ branches/gsoc10-mpwa/mpwa/app/sweepers/ticket_sweeper.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -0,0 +1,21 @@ +class PortSweeper < ActionController::Caching::Sweeper + observe Ticket + + def after_create(ticket) + expire_cache_for ticket.port + end + + def after_update(ticket) + expire_cache_for ticket.port + end + + def after_destroy(ticket) + expire_cache_for ticket.port + end + +private + def expire_cache_for(ticket) + expire_page :controller => :port, :action => :index + expire_page :controller => :port, :action => :show + end +end \ No newline at end of file Modified: branches/gsoc10-mpwa/mpwa/config/environment.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/config/environment.rb 2010-08-08 01:14:34 UTC (rev 70390) +++ branches/gsoc10-mpwa/mpwa/config/environment.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -10,5 +10,6 @@ config.gem 'recaptcha', :lib => "recaptcha/rails" config.gem 'will_paginate' + config.load_paths += %W( #{RAILS_ROOT}/app/sweepers ) config.time_zone = 'UTC' end \ No newline at end of file Modified: branches/gsoc10-mpwa/mpwa/config/environments/development.rb =================================================================== --- branches/gsoc10-mpwa/mpwa/config/environments/development.rb 2010-08-08 01:14:34 UTC (rev 70390) +++ branches/gsoc10-mpwa/mpwa/config/environments/development.rb 2010-08-08 05:16:51 UTC (rev 70391) @@ -11,7 +11,7 @@ # Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_view.debug_rjs = true -config.action_controller.perform_caching = false +config.action_controller.perform_caching = true # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false \ No newline at end of file