ref: master
app/sweepers/friendship_sweeper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
class FriendshipSweeper < ActiveRecord::Observer observe :friendship include SweeperHelper def after_create(friendship) expire_caches(friendship) end def after_destroy(friendship) if friendship.person expire_cache(friendship.person) end end protected def expire_caches(friendship) [friendship.person, friendship.friend].each do |profile| if profile expire_cache(profile) end end end def expire_cache(profile) # public friends page pages = profile.friends.count / Noosfero::Constants::PROFILE_PER_PAGE + 1 (1..pages).each do |i| expire_timeout_fragment(profile.friends_cache_key(:npage => i.to_s)) end # manage friends page pages = profile.friends.count / Noosfero::Constants::PROFILE_PER_PAGE + 1 (1..pages).each do |i| expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) end expire_blocks_cache(profile, [:profile]) end end |