Commit 873bdbb591bcd23a5596e5212e9c1939d08bdc2f

Authored by Antonio Terceiro
1 parent 01946cfc

Remove timed_cached_fragment plugin

In Rails 2.3 the memcache driver already supports adding timeout to
cache keys.
app/helpers/application_helper.rb
@@ -1310,4 +1310,8 @@ module ApplicationHelper @@ -1310,4 +1310,8 @@ module ApplicationHelper
1310 ) + content_tag('span', ' | ', :class => 'comment-footer comment-footer-hide') 1310 ) + content_tag('span', ' | ', :class => 'comment-footer comment-footer-hide')
1311 end 1311 end
1312 end 1312 end
  1313 +
  1314 + def cache_timeout(key, timeout, &block)
  1315 + cache(key, { :expires_in => timeout }, &block)
  1316 + end
1313 end 1317 end
app/helpers/sweeper_helper.rb
@@ -4,9 +4,7 @@ module SweeperHelper @@ -4,9 +4,7 @@ module SweeperHelper
4 ActionController::Base.new().expire_fragment(*args) 4 ActionController::Base.new().expire_fragment(*args)
5 end 5 end
6 6
7 - def expire_timeout_fragment(*args)  
8 - ActionController::Base.new().expire_timeout_fragment(*args)  
9 - end 7 + alias :expire_timeout_fragment :expire_fragment
10 8
11 def expire_friends(profile) 9 def expire_friends(profile)
12 # public friends page 10 # public friends page
app/views/friends/index.rhtml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 <h1><%= __("%s's friends") % profile.name %></h1> 3 <h1><%= __("%s's friends") % profile.name %></h1>
4 4
5 -<% cache_timeout(profile.manage_friends_cache_key(params), 4.hours.from_now) do %> 5 +<% cache_timeout(profile.manage_friends_cache_key(params), 4.hours) do %>
6 <% if @friends.empty? %> 6 <% if @friends.empty? %>
7 <p> 7 <p>
8 <em> 8 <em>
app/views/profile/_common.rhtml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 </script> 9 </script>
10 10
11 <% unless @action %> 11 <% unless @action %>
12 - <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours.from_now) do %> 12 + <% cache_timeout(profile.cache_key + '-profile-general-info', 4.hours) do %>
13 <tr> 13 <tr>
14 <th colspan='2'> 14 <th colspan='2'>
15 <%= _('Content') %> 15 <%= _('Content') %>
app/views/profile/_person_profile.rhtml
@@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
23 <%= display_field(_('e-Mail:'), profile, :email, true) { |email| link_to_email(email) } %> 23 <%= display_field(_('e-Mail:'), profile, :email, true) { |email| link_to_email(email) } %>
24 <% end %> 24 <% end %>
25 25
26 - <% cache_timeout(profile.relationships_cache_key, 4.hours.from_now) do %> 26 + <% cache_timeout(profile.relationships_cache_key, 4.hours) do %>
27 <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %> 27 <% if !(profile.organization.blank? && profile.organization_website.blank?) && (profile.active_fields.include?('organization') || profile.active_fields.include?('organization_website')) %>
28 <tr> 28 <tr>
29 <th colspan='2'><%= _('Work')%></th> 29 <th colspan='2'><%= _('Work')%></th>
app/views/profile/communities.rhtml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 <h1><%= _("%s's communities") % profile.name %></h1> 3 <h1><%= _("%s's communities") % profile.name %></h1>
4 4
5 -<% cache_timeout(profile.communities_cache_key(params), 4.hour.from_now) do %> 5 +<% cache_timeout(profile.communities_cache_key(params), 4.hour) do %>
6 <ul class='profile-list'> 6 <ul class='profile-list'>
7 <% @communities.each do |community| %> 7 <% @communities.each do |community| %>
8 <li><%= profile_image_link(community)%></li> 8 <li><%= profile_image_link(community)%></li>
app/views/profile/content_tagged.rhtml
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <%= link_to image_tag('icons-mime/rss-feed.png', :alt => _('Feed for this tag'), :title => _('Feed for this tag')), tag_feed_path, :class => 'blog-feed-link'%> 6 <%= link_to image_tag('icons-mime/rss-feed.png', :alt => _('Feed for this tag'), :title => _('Feed for this tag')), tag_feed_path, :class => 'blog-feed-link'%>
7 </p> 7 </p>
8 8
9 -<% cache_timeout(@tag_cache_key, 4.hour.from_now) do %> 9 +<% cache_timeout(@tag_cache_key, 4.hour) do %>
10 <div class='search-tagged-items'> 10 <div class='search-tagged-items'>
11 <ul> 11 <ul>
12 <% for doc in @tagged %> 12 <% for doc in @tagged %>
app/views/profile/friends.rhtml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 <h1><%= __("%s's friends") % profile.name %></h1> 3 <h1><%= __("%s's friends") % profile.name %></h1>
4 4
5 -<% cache_timeout(profile.friends_cache_key(params), 4.hours.from_now) do %> 5 +<% cache_timeout(profile.friends_cache_key(params), 4.hours) do %>
6 <ul class='profile-list'> 6 <ul class='profile-list'>
7 <% @friends.each do |friend| %> 7 <% @friends.each do |friend| %>
8 <%= profile_image_link(friend) %> 8 <%= profile_image_link(friend) %>
app/views/profile/members.rhtml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 <h1><%= _("%s's members") % profile.name %></h1> 3 <h1><%= _("%s's members") % profile.name %></h1>
4 4
5 -<% cache_timeout(profile.members_cache_key(params), 4.hours.from_now) do %> 5 +<% cache_timeout(profile.members_cache_key(params), 4.hours) do %>
6 <ul class='profile-list'> 6 <ul class='profile-list'>
7 <% @members.each do |member| %> 7 <% @members.each do |member| %>
8 <%= profile_image_link(member) %> 8 <%= profile_image_link(member) %>
app/views/profile/tags.rhtml
1 <h1><%= _("%s's tags") % @profile.name %></h1> 1 <h1><%= _("%s's tags") % @profile.name %></h1>
2 2
3 <div class='tag_cloud'> 3 <div class='tag_cloud'>
4 -<% cache_timeout(@tags_cache_key, 4.hour.from_now) do %> 4 +<% cache_timeout(@tags_cache_key, 4.hour) do %>
5 <%= tag_cloud @tags, :id, { :action => :tags }, {:show_count => true} %> 5 <%= tag_cloud @tags, :id, { :action => :tags }, {:show_count => true} %>
6 <% end %> 6 <% end %>
7 </div> 7 </div>
app/views/search/tag.rhtml
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <%= button('back', _('Back to tag cloud'), :action => 'tags') %> 6 <%= button('back', _('Back to tag cloud'), :action => 'tags') %>
7 <% end %> 7 <% end %>
8 8
9 -<% cache_timeout(@tag_cache_key, 4.hour.from_now) do %> 9 +<% cache_timeout(@tag_cache_key, 4.hour) do %>
10 <div class='search-tagged-items'> 10 <div class='search-tagged-items'>
11 <% @tagged.each do |hit| %> 11 <% @tagged.each do |hit| %>
12 <ul class="clean-list"> 12 <ul class="clean-list">
app/views/search/tags.rhtml
1 <h1><%= _('Tag cloud') %></h1> 1 <h1><%= _('Tag cloud') %></h1>
2 2
3 <div class='tag_cloud'> 3 <div class='tag_cloud'>
4 -<% cache_timeout(@tags_cache_key, 4.hour.from_now) do %> 4 +<% cache_timeout(@tags_cache_key, 4.hour) do %>
5 <%= tag_cloud @tags, :tag, {:action => 'tag'}, {:show_count => true} %> 5 <%= tag_cloud @tags, :tag, {:action => 'tag'}, {:show_count => true} %>
6 <% end %> 6 <% end %>
7 </div> 7 </div>
app/views/shared/block.rhtml
1 <% if block.cacheable? && use_cache %> 1 <% if block.cacheable? && use_cache %>
2 - <% cache_timeout(block.cache_key, block.timeout.from_now) do %> 2 + <% cache_timeout(block.cache_key, block.timeout) do %>
3 <%= display_block_content(block, main_content) %> 3 <%= display_block_content(block, main_content) %>
4 <% end %> 4 <% end %>
5 <% else %> 5 <% else %>
vendor/plugins/timed_cached_fragment/README
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -TimedCacheFragment  
2 -==================  
3 -  
4 -In Rails, caching is one of those things that is made pretty easy, but can also be difficult when you want to do complex tasks with the caching -- such as expiring it. There are two ways with expire_fragment within the logic of your controllers or using an Observers.  
5 -  
6 -This plugin allows caching to be expired on predefined time limit. The idea is that the caching takes cared of the expiration instead of writing conditions in the controller. I understand that it goes against the idea of why the caching mechanism does not have them now.  
7 -  
8 -To the plugin. Its an extension of cache method that has logic for the time limit. The method to use within views is called cache_timeout. The first argument of the method is the regular Hash/String of the cache key and the second argument is the timeout value (being a Time class value).  
9 -  
10 -Example usage:  
11 -  
12 -# This is last 5 minutes of posts from our forums:  
13 - <%cache_timeout('forum_listing',5.minutes.from_now) do %>  
14 - <ul>  
15 - <% for post in @posts %>  
16 - <li><b><%=post.title%></b> - by <%=post.author.username%> at <%=post.created_at></p></li>  
17 - <%end%>  
18 - </ul>  
19 - <%end%>  
20 -  
21 -To enforce the timeout cache value within the controller don't use the read_fragment method -- unless really needed. The method that is provided to check that the timeout value has is expired is is_cache_expired?. The method takes the argument of the cache key.  
22 -  
23 -Example Usage within controller:  
24 -  
25 -def list  
26 - if is_cache_expired?('forum_listing')  
27 - @posts = Post.find(:all)  
28 - end  
29 -end  
30 \ No newline at end of file 0 \ No newline at end of file
vendor/plugins/timed_cached_fragment/Rakefile
@@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
1 -require 'rake'  
2 -require 'rake/testtask'  
3 -require 'rake/rdoctask'  
4 -  
5 -desc 'Default: run unit tests.'  
6 -task :default => :test  
7 -  
8 -desc 'Test the timed_cache_fragment plugin.'  
9 -Rake::TestTask.new(:test) do |t|  
10 - t.libs << 'lib'  
11 - t.pattern = 'test/**/*_test.rb'  
12 - t.verbose = true  
13 -end  
14 -  
15 -desc 'Generate documentation for the timed_cache_fragment plugin.'  
16 -Rake::RDocTask.new(:rdoc) do |rdoc|  
17 - rdoc.rdoc_dir = 'rdoc'  
18 - rdoc.title = 'TimedCacheFragment'  
19 - rdoc.options << '--line-numbers' << '--inline-source'  
20 - rdoc.rdoc_files.include('README')  
21 - rdoc.rdoc_files.include('lib/**/*.rb')  
22 -end  
vendor/plugins/timed_cached_fragment/init.rb
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -# Include hook code here  
2 -require 'timed_cache_fragment'  
3 \ No newline at end of file 0 \ No newline at end of file
vendor/plugins/timed_cached_fragment/install.rb
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -# Install hook code here  
vendor/plugins/timed_cached_fragment/lib/timed_cache_fragment.rb
@@ -1,75 +0,0 @@ @@ -1,75 +0,0 @@
1 -# TimedCacheFragment  
2 -module ActionController  
3 - module Cache  
4 - module TimedCache  
5 - #handles standard ERB fragments used in RHTML  
6 - def cache_timeout(key={}, expire = 10.minutes.from_now, &block)  
7 - unless perform_caching then block.call; return end  
8 - if is_cache_expired?(key,true)  
9 - expire_timeout_fragment(key)  
10 - set_timeout(key, expire)  
11 - end  
12 - cache_erb_fragment(block,key)  
13 - end  
14 - #handles the expiration of timeout fragment  
15 - def expire_timeout_fragment(key)  
16 - delete_timeout(key)  
17 - expire_fragment(key)  
18 - end  
19 - #checks to see if a cache has fully expired  
20 - def is_cache_expired?(name, is_key = false)  
21 - key = is_key ? name : fragment_cache_key(name)  
22 - return true unless read_fragment(key)  
23 - timeout = get_timeout(key)  
24 - return (!timeout) || (timeout < Time.now)  
25 - end  
26 -  
27 - # from http://code.google.com/p/timedcachedfragment/issues/detail?id=1  
28 - def cache_erb_fragment(block, name = {}, options = nil)  
29 - unless perform_caching then block.call; return end  
30 -  
31 - buffer = eval(ActionView::Base.erb_variable, block.binding)  
32 -  
33 - if cache = read_fragment(name, options)  
34 - buffer.concat(cache)  
35 - else  
36 - pos = buffer.length  
37 - block.call  
38 - write_fragment(name, buffer[pos..-1], options)  
39 - end  
40 - end  
41 -  
42 - def delete_timeout(key)  
43 - expire_fragment('timeout:' + key)  
44 - end  
45 - def get_timeout(key)  
46 - frag = read_fragment('timeout:' + key)  
47 - frag ? frag.to_time : nil  
48 - end  
49 - def set_timeout(key, value)  
50 - write_fragment('timeout:' + key, value)  
51 - end  
52 -  
53 - end  
54 - end  
55 -end  
56 -  
57 -  
58 -module ActionView  
59 - module Helpers  
60 - module TimedCacheHelper  
61 - def is_cache_expired?(name = nil)  
62 - return false if name.nil?  
63 - key = fragment_cache_key(name)  
64 - return @controller.send('is_cache_expired?', key)  
65 - end  
66 - def cache_timeout(name,expire=10.minutes.from_now, &block)  
67 - @controller.cache_timeout(name,expire,&block)  
68 - end  
69 - end  
70 - end  
71 -end  
72 -  
73 -#add to the respective controllers  
74 -ActionView::Base.send(:include, ActionView::Helpers::TimedCacheHelper)  
75 -ActionController::Base.send(:include, ActionController::Cache::TimedCache)  
vendor/plugins/timed_cached_fragment/tasks/timed_cache_fragment_tasks.rake
@@ -1,4 +0,0 @@ @@ -1,4 +0,0 @@
1 -# desc "Explaining what the task does"  
2 -# task :timed_cache_fragment do  
3 -# # Task goes here  
4 -# end  
5 \ No newline at end of file 0 \ No newline at end of file
vendor/plugins/timed_cached_fragment/test/timed_cache_fragment_test.rb
@@ -1,8 +0,0 @@ @@ -1,8 +0,0 @@
1 -require 'test/unit'  
2 -  
3 -class TimedCacheFragmentTest < Test::Unit::TestCase  
4 - # Replace this with your real tests.  
5 - def test_this_plugin  
6 - flunk  
7 - end  
8 -end  
vendor/plugins/timed_cached_fragment/uninstall.rb
@@ -1 +0,0 @@ @@ -1 +0,0 @@
1 -# Uninstall hook code here