Commit d4d4cab12654c02591ec35c647d6b0a2e250c0a8

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 2fd72e94

ActionItem1205: fixing cache_timeout

* making profile index expire
app/helpers/sweeper_helper.rb
... ... @@ -43,4 +43,7 @@ module SweeperHelper
43 43 blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)}
44 44 end
45 45  
  46 + def expire_profile_index(profile)
  47 + expire_timeout_fragment(profile.relationships_cache_key)
  48 + end
46 49 end
... ...
app/models/person.rb
... ... @@ -275,4 +275,8 @@ class Person < Profile
275 275 page = params[:npage] || '1'
276 276 identifier + '-manage-friends-page-' + page
277 277 end
  278 +
  279 + def relationships_cache_key
  280 + identifier + '-profile-relationships'
  281 + end
278 282 end
... ...
app/sweepers/profile_sweeper.rb
... ... @@ -17,8 +17,11 @@ protected
17 17 profile.members.each do |member|
18 18 expire_communities(member) if profile.community?
19 19 expire_enterprises(member) if profile.enterprise?
  20 + expire_profile_index(member) if profile.enterprise?
20 21 end
21 22  
  23 + expire_profile_index(profile) if profile.person?
  24 +
22 25 profile.blocks.each do |block|
23 26 expire_timeout_fragment(block.cache_keys)
24 27 end
... ...
app/views/profile/_person.rhtml
... ... @@ -16,7 +16,7 @@
16 16 <%= display_field(_('e-Mail:'), profile, :email, true) { |email| link_to_email(email) } %>
17 17 <% end %>
18 18  
19   -<% cache_timeout(profile.identifier + '-profile-relationships', 4.hours.from_now) do %>
  19 +<% cache_timeout(profile.relationships_cache_key, 4.hours.from_now) do %>
20 20 <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %>
21 21 <tr>
22 22 <th colspan='2'><%= _('Work')%></th>
... ...
vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb
... ... @@ -3,14 +3,13 @@ module ActionController
3 3 module Cache
4 4 module TimedCache
5 5 #handles standard ERB fragments used in RHTML
6   - def cache_timeout(name={}, expire = 10.minutes.from_now, &block)
  6 + def cache_timeout(key={}, expire = 10.minutes.from_now, &block)
7 7 unless perform_caching then block.call; return end
8   - key = fragment_cache_key(name)
9 8 if is_cache_expired?(key,true)
10 9 expire_timeout_fragment(key)
11 10 set_timeout(key, expire)
12 11 end
13   - cache_erb_fragment(block,name)
  12 + cache_erb_fragment(block,key)
14 13 end
15 14 #handles the expiration of timeout fragment
16 15 def expire_timeout_fragment(key)
... ...