Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
improving sweapers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcansky committed Feb 16, 2011
1 parent 36c9ae9 commit b89fb2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/sweepers/bookmark_sweeper.rb
Expand Up @@ -2,16 +2,19 @@ class BookmarkSweeper < ActionController::Caching::Sweeper
observe Bookmark observe Bookmark
# If our sweeper detects that a Bookmark was created call this # If our sweeper detects that a Bookmark was created call this
def after_create(bookmark) def after_create(bookmark)
expire_fragment(%r{.*post.*})
expire_cache_for(bookmark) expire_cache_for(bookmark)
end end


# If our sweeper detects that a Bookmark was updated call this # If our sweeper detects that a Bookmark was updated call this
def after_update(bookmark) def after_update(bookmark)
expire_fragment(%r{.*post.*})
expire_cache_for(bookmark) expire_cache_for(bookmark)
end end


# If our sweeper detects that a Bookmark was deleted call this # If our sweeper detects that a Bookmark was deleted call this
def after_destroy(bookmark) def after_destroy(bookmark)
expire_fragment(%r{.*post.*})
expire_cache_for(bookmark) expire_cache_for(bookmark)
end end


Expand Down
4 changes: 2 additions & 2 deletions app/views/application/index.haml
Expand Up @@ -6,13 +6,13 @@
%h2 Last 20 bookmarks %h2 Last 20 bookmarks


- if current_user - 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 %div.posts
- @posts.each do |post| - @posts.each do |post|
%div.bookmark %div.bookmark
= render "/posts/short_post", :post => post = render "/posts/short_post", :post => post
- else - 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 %div.posts
- @posts.each do |post| - @posts.each do |post|
%div.bookmark %div.bookmark
Expand Down
8 changes: 4 additions & 4 deletions app/views/posts/index.haml
Expand Up @@ -21,23 +21,23 @@


- if (params[:tag] || params[:username] || params[:fromdt] || params[:todt] || params[:page]) - if (params[:tag] || params[:username] || params[:fromdt] || params[:todt] || params[:page])
- if current_user - 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 = render "posts/posts_short", :posts => @posts
.pagination .pagination
= will_paginate(@posts) = will_paginate(@posts)
- else - 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 = render "posts/posts_short", :posts => @posts
.pagination .pagination
= will_paginate(@posts) = will_paginate(@posts)
- else - else
- if current_user - 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 = render "posts/posts_short", :posts => @posts
.pagination .pagination
= will_paginate(@posts) = will_paginate(@posts)
- else - 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 = render "posts/posts_short", :posts => @posts
.pagination .pagination
= will_paginate(@posts) = will_paginate(@posts)
Expand Down

0 comments on commit b89fb2c

Please sign in to comment.