Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improving sweapers

  • Loading branch information...
commit b89fb2cbb7a3cdca1bd5110b63bf847e8dcfdcd6 1 parent 36c9ae9
mcansky authored
View
3  app/sweepers/bookmark_sweeper.rb
@@ -2,16 +2,19 @@ class BookmarkSweeper < ActionController::Caching::Sweeper
observe Bookmark
# If our sweeper detects that a Bookmark was created call this
def after_create(bookmark)
+ expire_fragment(%r{.*post.*})
expire_cache_for(bookmark)
end
# If our sweeper detects that a Bookmark was updated call this
def after_update(bookmark)
+ expire_fragment(%r{.*post.*})
expire_cache_for(bookmark)
end
# If our sweeper detects that a Bookmark was deleted call this
def after_destroy(bookmark)
+ expire_fragment(%r{.*post.*})
expire_cache_for(bookmark)
end
View
4 app/views/application/index.haml
@@ -6,13 +6,13 @@
%h2 Last 20 bookmarks
- if current_user
- - cache(:action => 'index', :action_suffix => 'last_20_posts', :expires_in => 10.minute) do
+ - cache(:fragment => "last_20_posts", :expires_in => 10.minute) do
%div.posts
- @posts.each do |post|
%div.bookmark
= render "/posts/short_post", :post => post
- else
- - cache(:action => 'index', :action_suffix => 'public_last_20_posts', :expires_in => 10.minute) do
+ - cache(:fragment => "last_20_posts_public", :expires_in => 10.minute) do
%div.posts
- @posts.each do |post|
%div.bookmark
View
8 app/views/posts/index.haml
@@ -21,23 +21,23 @@
- if (params[:tag] || params[:username] || params[:fromdt] || params[:todt] || params[:page])
- if current_user
- - cache(:action => 'index', :action_suffix => params.to_s + "_#{current_user.id}", :expires_in => 10.minute) do
+ - cache(:fragment => params.to_s + "_#{current_user.id}_posts", :expires_in => 10.minute) do
= render "posts/posts_short", :posts => @posts
.pagination
= will_paginate(@posts)
- else
- - cache(:action => 'index', :action_suffix => params.to_s, :expires_in => 10.minute) do
+ - cache(:fragment => params.to_s + "_#{current_user.id}_posts", :expires_in => 10.minute) do
= render "posts/posts_short", :posts => @posts
.pagination
= will_paginate(@posts)
- else
- if current_user
- - cache(:action => 'index', :action_suffix => "all_user_#{current_user.id}_posts", :expires_in => 10.minute) do
+ - cache(:fragment => "all_user_#{current_user.id}_posts", :expires_in => 10.minute) do
= render "posts/posts_short", :posts => @posts
.pagination
= will_paginate(@posts)
- else
- - cache(:action => 'index', :action_suffix => "public_all_post", :expires_in => 10.minute) do
+ - cache(:fragment => "public_all_posts", :expires_in => 10.minute) do
= render "posts/posts_short", :posts => @posts
.pagination
= will_paginate(@posts)
Please sign in to comment.
Something went wrong with that request. Please try again.