Merge pull request #232 from Growstuff/dev

Caching for homepage
This commit is contained in:
Skud
2013-06-07 02:16:43 -07:00
11 changed files with 83 additions and 31 deletions

View File

@@ -17,14 +17,12 @@ gem 'activemerchant', '1.33.0',
gem 'active_utils', '1.0.5',
:path => 'vendor/gems/active_utils-1.0.5'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :production, :staging do
gem 'pg'
gem 'newrelic_rpm'
gem 'unicorn'
gem 'dalli'
gem 'memcachier'
end
# Gems used only for assets and not required

View File

@@ -74,6 +74,7 @@ GEM
compass (>= 0.12.2, < 0.14)
daemon_controller (1.1.2)
daemons (1.1.9)
dalli (2.6.4)
debugger (1.5.0)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
@@ -128,6 +129,7 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
memcachier (0.0.2)
mime-types (1.21)
multi_json (1.7.1)
net-scp (1.1.0)
@@ -256,6 +258,7 @@ DEPENDENCIES
capistrano-ext
coffee-rails (~> 3.2.1)
compass-rails (~> 1.0.3)
dalli
debugger
devise
diff-lcs
@@ -269,6 +272,7 @@ DEPENDENCIES
jquery-rails
json (~> 1.7.7)
less-rails
memcachier
newrelic_rpm
omniauth
omniauth-flickr

View File

@@ -1,5 +1,8 @@
class PlantingsController < ApplicationController
load_and_authorize_resource
cache_sweeper :planting_sweeper
# GET /plantings
# GET /plantings.json
def index

View File

@@ -1,5 +1,8 @@
class PostsController < ApplicationController
load_and_authorize_resource
cache_sweeper :post_sweeper
# GET /posts
# GET /posts.json

View File

@@ -0,0 +1,21 @@
class PlantingSweeper < ActionController::Caching::Sweeper
observe Planting
def after_create(planting)
expire_cache_for(planting)
end
def after_update(planting)
expire_cache_for(planting)
end
def after_destroy(planting)
expire_cache_for(planting)
end
private
def expire_cache_for(planting)
expire_fragment('recent_plantings')
end
end

View File

@@ -0,0 +1,16 @@
class PostSweeper < ActionController::Caching::Sweeper
observe Post
def after_create(post)
expire_fragment('recent_posts')
end
def after_update(post)
expire_fragment('recent_posts')
end
def after_destroy(post)
expire_fragment('recent_posts')
end
end

View File

@@ -1,12 +1,14 @@
- if @plantings
%ul
- @plantings.each do |p|
%li
= link_to "#{p.crop_system_name} in #{p.location}", p
- if p.planted_at
on
= p.planted_at
- else
%p None yet.
- cache('recent_plantings') do
- if @plantings
%ul
- @plantings.each do |p|
%li
= link_to "#{p.crop_system_name} in #{p.location}", p
- if p.planted_at
on
= p.planted_at
- else
%p None yet.
- if can? :create, Planting
%p= link_to "Plant something", new_planting_path, :class => 'btn btn-primary'

View File

@@ -1,17 +1,19 @@
- if @posts
%ul
- @posts.each do |p|
%li
= link_to p.subject, p
- unless @member
posted by
= link_to p.author, p.author
- if p.forum
in
= link_to p.forum.name, p.forum
on
= p.created_at.to_s(:date)
- else
%p None yet.
- cache('recent_posts') do
- if @posts
%ul
- @posts.each do |p|
%li
= link_to p.subject, p
- unless @member
posted by
= link_to p.author, p.author
- if p.forum
in
= link_to p.forum.name, p.forum
on
= p.created_at.to_s(:date)
- else
%p None yet.
- if can? :create, Post
%p= link_to "Post something", new_post_path, :class => 'btn btn-primary'

View File

@@ -11,7 +11,10 @@ Growstuff::Application.configure do
# Show full error reports and disable caching
config.consider_all_requests_local = true
# cache for testing/experimentation - turn off for normal dev use
config.action_controller.perform_caching = false
config.cache_store = :memory_store
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

View File

@@ -40,7 +40,7 @@ Growstuff::Application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
config.cache_store = :dalli_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"

View File

@@ -40,7 +40,7 @@ Growstuff::Application.configure do
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
config.cache_store = :dalli_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"