You are viewing a plain text version of this content. The canonical link for it is here.
Posted to olio-commits@incubator.apache.org by ws...@apache.org on 2009/03/15 17:17:22 UTC
svn commit: r754694 - in /incubator/olio/webapp/rails/branches/caching:
app/controllers/ app/helpers/ app/views/comments/ app/views/events/
app/views/layouts/ config/environments/
vendor/plugins/extended_fragment_cache/ vendor/plugins/extended_fragment...
Author: wsobel
Date: Sun Mar 15 17:17:21 2009
New Revision: 754694
URL: http://svn.apache.org/viewvc?rev=754694&view=rev
Log:
Fix for OLIO-59: Updated caching and fixed configuration
Added:
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/.gitignore
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/CHANGELOG
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/LICENSE
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/README
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/Rakefile
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/VERSION.yml
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/extended_fragment_cache.gemspec
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/init.rb
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/install.rb
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/extended_fragment_cache.rb
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/pkg/
incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/pkg/extended_fragment_cache-0.3.0.gem (with props)
Modified:
incubator/olio/webapp/rails/branches/caching/app/controllers/events_controller.rb
incubator/olio/webapp/rails/branches/caching/app/controllers/users_controller.rb
incubator/olio/webapp/rails/branches/caching/app/helpers/events_helper.rb
incubator/olio/webapp/rails/branches/caching/app/views/comments/_list.html.erb
incubator/olio/webapp/rails/branches/caching/app/views/events/_event_list.html.erb
incubator/olio/webapp/rails/branches/caching/app/views/events/_filtered_events.html.erb
incubator/olio/webapp/rails/branches/caching/app/views/events/show.html.erb
incubator/olio/webapp/rails/branches/caching/app/views/layouts/site.rhtml
incubator/olio/webapp/rails/branches/caching/config/environments/production.rb
Modified: incubator/olio/webapp/rails/branches/caching/app/controllers/events_controller.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/controllers/events_controller.rb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/controllers/events_controller.rb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/controllers/events_controller.rb Sun Mar 15 17:17:21 2009
@@ -313,7 +313,7 @@
session[:order] = params[:order] || session[:order] || 'event_date'
- @events = Event.paginate :page => params[:page], :conditions => conditions, :order => session[:order], :per_page => 10, :include => [:address, :image]
+ @events = lazy { Event.paginate :page => params[:page], :conditions => conditions, :order => session[:order], :per_page => 10, :include => [:address, :image] }
if @zipcode and !@zipcode.empty?
@events.delete_if { |e| e.address.zip != @zipcode }
end
Modified: incubator/olio/webapp/rails/branches/caching/app/controllers/users_controller.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/controllers/users_controller.rb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/controllers/users_controller.rb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/controllers/users_controller.rb Sun Mar 15 17:17:21 2009
@@ -155,7 +155,11 @@
session[:original_uri] = nil
flash[:notice] = "Successfully logged in!"
- redirect_to(uri || events_path)
+ if CACHED
+ redirect_to(uri || home_path)
+ else
+ redirect_to(uri || events_path)
+ end
else
user = nil
params[:email] = nil
Modified: incubator/olio/webapp/rails/branches/caching/app/helpers/events_helper.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/helpers/events_helper.rb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/helpers/events_helper.rb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/helpers/events_helper.rb Sun Mar 15 17:17:21 2009
@@ -5,11 +5,11 @@
if logged_in?
attending = @attendees.find { |u| u.id == session[:user_id] }
if attending
- links += form_remote_tag :url => unattend_event_path(event), :method => :post, :html => {:method => :post}
+ links += form_remote_tag :url => unattend_event_path(event.id), :method => :post, :html => {:method => :post}
links += submit_tag "Unattend"
links += "</form>"
else
- links += form_remote_tag :url => attend_event_path(event), :method => :post, :html => {:method => :post}
+ links += form_remote_tag :url => attend_event_path(event.id), :method => :post, :html => {:method => :post}
links += submit_tag "Attend"
links += "</form>"
end
Modified: incubator/olio/webapp/rails/branches/caching/app/views/comments/_list.html.erb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/views/comments/_list.html.erb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/views/comments/_list.html.erb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/views/comments/_list.html.erb Sun Mar 15 17:17:21 2009
@@ -1,6 +1,6 @@
<h2 class="event_detail_heading">Comments</h2>
-<% cache({:controller => "events", :action => "show", :id => @event.id, :part => "event_comments"}, {:expire => 30.seconds.to_i}) do -%>
+<% cache({:controller => "events", :action => "show", :id => params[:id], :part => "event_comments"}, {:expire => 30.seconds.to_i}) do -%>
<% if @comments.nil? or @comments.empty? -%>
<span class="subliminal">There are no comments for this event.</span>
Modified: incubator/olio/webapp/rails/branches/caching/app/views/events/_event_list.html.erb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/views/events/_event_list.html.erb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/views/events/_event_list.html.erb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/views/events/_event_list.html.erb Sun Mar 15 17:17:21 2009
@@ -15,15 +15,13 @@
<%= zipcode_filter(@zipcode) %>
<br />
- <% unless @events.empty? -%>
- <% unless @date -%>
- Sort:
- <%= created_at_radio_button %>
- Created Date
-
- <%= event_date_radio_button %>
- Event Date
- <% end -%>
+ <% unless @date -%>
+ Sort:
+ <%= created_at_radio_button %>
+ Created Date
+
+ <%= event_date_radio_button %>
+ Event Date
<% end -%>
<% if @date -%>
<input type="hidden" name="month" value="<%= month %>" />
Modified: incubator/olio/webapp/rails/branches/caching/app/views/events/_filtered_events.html.erb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/views/events/_filtered_events.html.erb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/views/events/_filtered_events.html.erb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/views/events/_filtered_events.html.erb Sun Mar 15 17:17:21 2009
@@ -1,32 +1,34 @@
-<div id="event_table">
- <% if @events.empty? -%>
- No events.
- <% else -%>
- <ol id="event_list" style="list-style-type: none;">
- <% @events.each do |event| -%>
- <% which_class = cycle('even_event', 'odd_event') -%>
- <li id="event_<%= event.id %>_details" class="event_item <%= which_class %>" style="padding: 7px;" onmouseover="Element.findChildren(this, 'extra_details', true, 'div').first().show();" onmouseout="Element.findChildren(this, 'extra_details', true, 'div').first().hide();">
- <div class="thumbnail_for_list">
- <%= thumbnail(get_image(event), event_path(event), :small) %>
- </div>
- <div class="event_details_for_list">
- <h2 class="tight_heading"><%= link_to h(event.title), event %></h2>
- <%= simple_date(event.event_timestamp) %>
+<% cache({:controller => "events", :action => "index", :part => "index_event_list"}, {:expire => 30.seconds.to_i}) do -%>
+ <div id="event_table">
+ <% if @events.empty? -%>
+ No events.
+ <% else -%>
+ <ol id="event_list" style="list-style-type: none;">
+ <% @events.each do |event| -%>
+ <% which_class = cycle('even_event', 'odd_event') -%>
+ <li id="event_<%= event.id %>_details" class="event_item <%= which_class %>" style="padding: 7px;" onmouseover="Element.findChildren(this, 'extra_details', true, 'div').first().show();" onmouseout="Element.findChildren(this, 'extra_details', true, 'div').first().hide();">
+ <div class="thumbnail_for_list">
+ <%= thumbnail(get_image(event), event_path(event), :small) %>
+ </div>
+ <div class="event_details_for_list">
+ <h2 class="tight_heading"><%= link_to h(event.title), event %></h2>
+ <%= simple_date(event.event_timestamp) %>
- <div class="extra_details" style="display: none;">
- <%= edit_delete_links(event) if logged_in? %>
- <br />
- Created: <%= output_date(event.created_at) %> <br/><br/>
- <%=white_list event.summary %>
+ <div class="extra_details" style="display: none;">
+ <%= edit_delete_links(event) if logged_in? %>
+ <br />
+ Created: <%= output_date(event.created_at) %> <br/><br/>
+ <%=white_list event.summary %>
+ </div>
</div>
- </div>
- <div class="clr"></div>
- </li>
- <% if which_class == 'odd_event' -%>
- <li class="clr"></li>
+ <div class="clr"></div>
+ </li>
+ <% if which_class == 'odd_event' -%>
+ <li class="clr"></li>
+ <% end -%>
<% end -%>
+ </ol>
<% end -%>
- </ol>
- <% end -%>
- <%= will_paginate @events if @events.respond_to? :page_count %>
-</div>
+ <%= will_paginate @events if @events.respond_to? :page_count %>
+ </div>
+<% end -%>
\ No newline at end of file
Modified: incubator/olio/webapp/rails/branches/caching/app/views/events/show.html.erb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/views/events/show.html.erb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/views/events/show.html.erb (original)
+++ incubator/olio/webapp/rails/branches/caching/app/views/events/show.html.erb Sun Mar 15 17:17:21 2009
@@ -1,5 +1,5 @@
<div id="event_header">
- <% cache({:controller => "events", :action => "show", :id => params[:id], :part => "main_event_details", :creator => (session[:user_id] && @event.user_id == session[:user_id])}, {:expire => 30.seconds.to_i}) do -%>
+ <% cache({:controller => "events", :action => "show", :id => params[:id], :part => "main_event_details", :creator => (session[:user_id])}, {:expire => 30.seconds.to_i}) do -%>
<div id="event_thumbnail"><%= thumbnail(@event.image) %></div>
<div id="main_event_details">
<h1 class="inline"><%=h @event.title %></h1> <%= edit_delete_links(@event) %>
@@ -64,7 +64,7 @@
<% if logged_in? -%>
<%=
link_to_function "Add a comment",
- :href => new_event_comment_path(@event),
+ :href => new_event_comment_path(params[:id]),
:method => :get, :id => "comment_link" do |page|
page[:comment_form].visual_effect :blind_down
page[:comment_add_link].hide
Modified: incubator/olio/webapp/rails/branches/caching/app/views/layouts/site.rhtml
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/app/views/layouts/site.rhtml?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/app/views/layouts/site.rhtml (original)
+++ incubator/olio/webapp/rails/branches/caching/app/views/layouts/site.rhtml Sun Mar 15 17:17:21 2009
@@ -23,12 +23,13 @@
<% end -%>
<ul id="main_nav">
- <li><%= link_to 'Home', events_path %></li>
<% if logged_in? -%>
+ <li><%= link_to 'Home', home_path %></li>
<li><%= link_to 'Add Event', new_event_path %></li>
<li><%= link_to 'Users', search_users_path %></li>
<li><%= link_to 'Edit Profile', edit_user_path(session[:user_id]) %></li>
<% else -%>
+ <li><%= link_to 'Home', events_path %></li>
<li><%= link_to 'Register', new_user_path %></li>
<% end -%>
</ul>
Modified: incubator/olio/webapp/rails/branches/caching/config/environments/production.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/config/environments/production.rb?rev=754694&r1=754693&r2=754694&view=diff
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/config/environments/production.rb (original)
+++ incubator/olio/webapp/rails/branches/caching/config/environments/production.rb Sun Mar 15 17:17:21 2009
@@ -18,7 +18,7 @@
# Disable delivery errors, bad email addresses will be ignored
if CACHED
if MEMCACHED
- config.action_controller.cache_store = :mem_cache_store, 'r5.millennium.berkeley,edu'
+ config.action_controller.cache_store = :mem_cache_store, 'localhost'
else
config.action_mailer.raise_delivery_errors = false
config.action_controller.cache_store = :file_store, RAILS_ROOT + '/tmp/cache/'
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/.gitignore
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/.gitignore?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/.gitignore (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/.gitignore Sun Mar 15 17:17:21 2009
@@ -0,0 +1,3 @@
+*.sw?
+.DS_Store
+coverage
\ No newline at end of file
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/CHANGELOG?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/CHANGELOG (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/CHANGELOG Sun Mar 15 17:17:21 2009
@@ -0,0 +1,4 @@
+0.3.1
+- content interpolation uses gsub! instead of sub! - all occurrences of keys are now replaced
+0.3.0
+- updated to work with Rails 2.2
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/LICENSE
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/LICENSE?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/LICENSE (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/LICENSE Sun Mar 15 17:17:21 2009
@@ -0,0 +1,20 @@
+Copyright (c) 2008 tylerkovacs
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/README
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/README?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/README (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/README Sun Mar 15 17:17:21 2009
@@ -0,0 +1,124 @@
+=ExtendedFragmentCache
+
+== About
+
+The extended_fragment_cache plugin provides content interpolation and an
+in-process memory cache for fragment caching. It also integrates the
+features of Yan Pritzker's memcache_fragments plugin since they both
+operate on the same methods.
+
+== Installation
+
+1. This plugin requires that the memcache-client gem is installed.
+ # gem install memcache-client
+
+2. Install the plugin OR the gem
+ # ./script/plugin install git://github.com/tylerkovacs/extended_fragment_cache.git (if running recent rails)
+ - OR -
+ # gem install extended_fragment_cache
+
+== In-Process Memory Cache for Fragment Caching
+
+Fragment caching has a slight inefficiency that requires two lookups
+within the fragment cache store to render a single cached fragment.
+The two cache lookups are:
+
+1. The read_fragment method invoked in a controller to determine if a
+ fragment has already been cached. e.g.,
+ unless read_fragment("/x/y/z")
+ ...
+ end
+2. The cache helper method invoked in a view that renders the fragment. e.g.,
+ <% cache("/x/y/z") do %>
+ ...
+ <% end %>
+
+This plugin adds an in-process cache that saves the value retrieved from
+the fragment cache store. The in-process cache has two benefits:
+
+1. It cuts in half the number of read requests sent to the fragment cache
+ store. This can result in a considerable saving for sites that make
+ heavy use of memcached.
+2. Retrieving the fragment from the in-process cache is faster than going
+ to fragment cache store. On a typical dev box, the savings are
+ relatively small but would be noticeable in standard production
+ environment using memcached (where the fragment cache could be remote)
+
+Peter Zaitsev has a great post comparing the latencies of different
+cache types on the MySQL Performance blog:
+http://www.mysqlperformanceblog.com/2006/08/09/cache-performance-comparison/
+
+The plugin automatically installs a before_filter on the ApplicationController
+that flushes the in-process memory cache at the start of every request.
+
+== Content Interpolation for Fragment Caching
+
+Many modern websites mix a lot of static and dynamic content. The more
+dynamic content you have in your site, the harder it becomes to implement
+caching. In an effort to scale, you've implemented fragment caching
+all over the place. Fragment caching can be difficult if your static content
+is interleaved with your dynamic content. Your views become littered
+with cache calls which not only hurts performance (multiple calls to the
+cache backend), it also makes them harder to read. Content
+interpolation allows you substitude dynamic content into cached fragment.
+
+Take this example view:
+<% cache("/first_part") do %>
+ This content is very expensive to generate, so let's fragment cache it.<br/>
+<% end %>
+<%= Time.now %><br/>
+<% cache("/second_part") do %>
+ This content is also very expensive to generate.<br/>
+<% end %>
+
+We can replace it with:
+<% cache("/only_part", {}, {"__TIME_GOES_HERE__" => Time.now}) do %>
+ This content is very expensive to generate, so let's fragment cache it.<br/>
+ __TIME_GOES_HERE__<br/>
+ This content is also very expensive to generate.<br/>
+<% end %>
+
+The latter is easier to read and induces less load on the cache backend.
+
+We use content interpolation at Zvents to speed up our JSON methods.
+Converting objects to JSON representation is notoriously slow.
+Unfortunately, in our application, each JSON request must return some unique
+data. This makes caching tedious because 99% of the content returned is
+static for a given object, but there's a little bit of dynamic data that
+must be sent back in each response. Using content interpolation, we cache
+the object in JSON format and substitue the dynamic values in the view.
+
+This plugin integrates Yan Pritzker's extension that allows content to be
+cached with an expiry time (from the memcache_fragments plugin) since they
+both operate on the same method. This allows you to do things like:
+
+<% cache("/only_part", {:expire => 15.minutes}) do %>
+ This content is very expensive to generate, so let's fragment cache it.
+<% end %>
+
+== Metadata ==
+
+Sometimes you want to store metadata alongside your cached fragments.
+Simply store a value in ApplicationController.fragment_cache_data. When
+the fragment is served out of the cache, the value written to
+ApplicationController.fragment_cache_data within the cache block will
+be accessible after the cache block.
+
+<% cache(cache_key, {:expire => 15.minutes}) do %>
+ <% ApplicationController.fragment_cache_data = "metadata goes here" %>
+ ... cached fragment ERB ...
+<% end %>
+
+metadata was <%= ApplicationController.fragment_cache_data %>
+
+== Bugs, Code and Contributing
+
+There's a RubyForge project set up at:
+
+http://rubyforge.org/projects/zventstools/
+
+Anonymous SVN access:
+
+$ svn checkout svn://rubyforge.org/var/svn/zventstools
+
+Author: Tyler Kovacs (tyler dot kovacs at gmail dot com)
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/Rakefile
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/Rakefile?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/Rakefile (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/Rakefile Sun Mar 15 17:17:21 2009
@@ -0,0 +1,40 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rcov/rcovtask'
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ s.name = "extended_fragment_cache"
+ s.summary = %Q{The extended_fragment_cache plugin provides content interpolation and an in-process memory cache for fragment caching.}
+ s.email = "tyler.kovacs@gmail.com"
+ s.homepage = "http://github.com/tylerkovacs/extended_fragment_cache"
+ s.description = "See README"
+ s.authors = ["tylerkovacs"]
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+end
+
+Rake::TestTask.new do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'extended_fragment_cache'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+Rcov::RcovTask.new do |t|
+ t.libs << 'test'
+ t.test_files = FileList['test/**/*_test.rb']
+ t.verbose = true
+end
+
+task :default => :rcov
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/VERSION.yml
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/VERSION.yml?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/VERSION.yml (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/VERSION.yml Sun Mar 15 17:17:21 2009
@@ -0,0 +1,4 @@
+---
+:major: 0
+:minor: 3
+:patch: 1
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/extended_fragment_cache.gemspec
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/extended_fragment_cache.gemspec?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/extended_fragment_cache.gemspec (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/extended_fragment_cache.gemspec Sun Mar 15 17:17:21 2009
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{extended_fragment_cache}
+ s.version = "0.3.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["tylerkovacs"]
+ s.date = %q{2009-02-11}
+ s.description = %q{See README}
+ s.email = %q{tyler.kovacs@gmail.com}
+ s.files = ["VERSION.yml", "lib/extended_fragment_cache.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{http://github.com/tylerkovacs/extended_fragment_cache}
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.1}
+ s.summary = %q{The extended_fragment_cache plugin provides content interpolation and an in-process memory cache for fragment caching.}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/init.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/init.rb?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/init.rb (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/init.rb Sun Mar 15 17:17:21 2009
@@ -0,0 +1,3 @@
+require 'extended_fragment_cache'
+
+ActionController::Base.send :include, ActionController::Caching::ExtendedFragments
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/install.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/install.rb?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/install.rb (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/install.rb Sun Mar 15 17:17:21 2009
@@ -0,0 +1 @@
+# Install hook code here
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/extended_fragment_cache.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/extended_fragment_cache.rb?rev=754694&view=auto
==============================================================================
--- incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/extended_fragment_cache.rb (added)
+++ incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/lib/extended_fragment_cache.rb Sun Mar 15 17:17:21 2009
@@ -0,0 +1,273 @@
+# In-Process Memory Cache for Fragment Caching
+#
+# Fragment caching has a slight inefficiency that requires two lookups
+# within the fragment cache store to render a single cached fragment.
+# The two cache lookups are:
+#
+# 1. The read_fragment method invoked in a controller to determine if a
+# fragment has already been cached. e.g.,
+# unless read_fragment("/x/y/z")
+# ...
+# end
+# 2. The cache helper method invoked in a view that renders the fragment. e.g.,
+# <% cache("/x/y/z") do %>
+# ...
+# <% end %>
+#
+# This plugin adds an in-process cache that saves the value retrieved from
+# the fragment cache store. The in-process cache has two benefits:
+#
+# 1. It cuts in half the number of read requests sent to the fragment cache
+# store. This can result in a considerable saving for sites that make
+# heavy use of memcached.
+# 2. Retrieving the fragment from the in-process cache is faster than going
+# to fragment cache store. On a typical dev box, the savings are
+# relatively small but would be noticeable in standard production
+# environment using memcached (where the fragment cache could be remote)
+#
+# Peter Zaitsev has a great post comparing the latencies of different
+# cache types on the MySQL Performance blog:
+# http://www.mysqlperformanceblog.com/2006/08/09/cache-performance-comparison/
+#
+# The plugin automatically installs a after_filter on the
+# ApplicationController that flushes the in-process memory cache at the
+# start of every request.
+
+module ActionController
+ module Caching
+ module ExtendedFragments
+ # Add a local_fragment_cache object and accessor.
+ def self.append_features(base) #:nodoc:
+ super
+ base.class_eval do
+ @@local_fragment_cache = {}
+ @@fragment_cache_data = nil
+ cattr_accessor :local_fragment_cache, :fragment_cache_data
+ end
+
+ # add an after filter to flush the local cache after every request
+ base.after_filter({}) do |c|
+ @@local_fragment_cache.clear
+ end
+ end
+ end
+
+ module Fragments
+ # Override read_fragment so that it checks the local_fragment_cache
+ # object before going to the fragment_cache_store backend.
+ # - also allow fragments to be read using a class method (from a model)
+ def read_fragment(name, options = nil)
+ name = url_for(name.merge({:only_path => true})) if name.class == Hash
+ ActionController::Caching::Fragments.read_fragment(name, options)
+ end
+
+ def self.read_fragment(name, options=nil)
+ return unless ApplicationController.perform_caching
+
+ key = self.fragment_cache_key(name)
+ content = ApplicationController.local_fragment_cache[key]
+ ApplicationController.benchmark "Fragment read: #{key}" do
+ if content.nil?
+ content = ActionController::Base.cache_store.read(key, options)
+ ApplicationController.local_fragment_cache[key] = content
+ end
+ end
+
+ if content.is_a?(Hash)
+ ApplicationController.fragment_cache_data = content[:data]
+ content[:body]
+ else
+ ApplicationController.fragment_cache_data = nil
+ content
+ end
+ rescue NameError => err
+ # ignore bogus uninitialized constant ApplicationController errors
+ end
+
+ def write_fragment(name, content, options=nil)
+ name = url_for(name.merge({:only_path => true})) if name.class == Hash
+ ActionController::Caching::Fragments.write_fragment(name, content, options)
+ rescue NameError => err
+ # ignore bogus uninitialized constant ApplicationController errors
+ # when running Rails outside of web container
+ end
+
+ def self.write_fragment(name, content, options = nil)
+ return unless ApplicationController.perform_caching
+
+ key = self.fragment_cache_key(name)
+
+ if ApplicationController.fragment_cache_data
+ content = {
+ :data => ApplicationController.fragment_cache_data,
+ :body => content
+ }
+ end
+
+ ApplicationController.benchmark "Cached fragment: #{key}" do
+ ApplicationController.local_fragment_cache[key] = content
+ ActionController::Base.cache_store.write(key, content, options)
+ end
+
+ content.is_a?(Hash) ? content[:body] : content
+ rescue NameError => err
+ # ignore bogus uninitialized constant ApplicationController errors
+ end
+
+ # Utility method needed by class methods
+ def self.fragment_cache_key(name)
+ name.is_a?(Hash) ? name.to_s : name
+ end
+
+ # Add expire_fragments as class method so that we can expire cached
+ # content from models, etc.
+ def self.expire_fragment(name, options = nil)
+ return unless ApplicationController.perform_caching
+
+ key = self.fragment_cache_key(name)
+
+ if key.is_a?(Regexp)
+ ApplicationController.benchmark "Expired fragments matching: #{key.source}" do
+ ActionController::Base.cache_store.delete_matched(key, options)
+ end
+ else
+ ApplicationController.benchmark "Expired fragment: #{key}" do
+ ActionController::Base.cache_store.delete(key, options)
+ end
+ end
+ rescue NameError => err
+ # ignore bogus uninitialized constant ApplicationController errors
+ end
+ end
+ end
+end
+
+# Content Interpolation for Fragment Caching
+#
+# Many modern websites mix a lot of static and dynamic content. The more
+# dynamic content you have in your site, the harder it becomes to implement
+# caching. In an effort to scale, you've implemented fragment caching
+# all over the place. Fragment caching can be difficult if your static content
+# is interleaved with your dynamic content. Your views become littered
+# with cache calls which not only hurts performance (multiple calls to the
+# cache backend), it also makes them harder to read. Content
+# interpolation allows you substitude dynamic content into cached fragment.
+#
+# Take this example view:
+# <% cache("/first_part") do %>
+# This content is very expensive to generate, so let's fragment cache it.<br/>
+# <% end %>
+# <%= Time.now %><br/>
+# <% cache("/second_part") do %>
+# This content is also very expensive to generate.<br/>
+# <% end %>
+#
+# We can replace it with:
+# <% cache("/only_part", {}, {"__TIME_GOES_HERE__" => Time.now}) do %>
+# This content is very expensive to generate, so let's fragment cache it.<br/>
+# __TIME_GOES_HERE__<br/>
+# This content is also very expensive to generate.<br/>
+# <% end %>
+#
+# The latter is easier to read and induces less load on the cache backend.
+#
+# We use content interpolation at Zvents to speed up our JSON methods.
+# Converting objects to JSON representation is notoriously slow.
+# Unfortunately, in our application, each JSON request must return some unique
+# data. This makes caching tedious because 99% of the content returned is
+# static for a given object, but there's a little bit of dynamic data that
+# must be sent back in the response. Using content interpolation, we cache
+# the object in JSON format and substitue the dynamic values in the view.
+#
+# This plugin integrates Yan Pritzker's extension that allows content to be
+# cached with an expiry time (from the memcache_fragments plugin) since they
+# both operate on the same method. This allows you to do things like:
+#
+# <% cache("/only_part", {:expire => 15.minutes}) do %>
+# This content is very expensive to generate, so let's fragment cache it.
+# <% end %>
+
+module ActionView
+ module Helpers
+ # See ActionController::Caching::Fragments for usage instructions.
+ module CacheHelper
+ def cache(key, options={}, interpolation={}, &block)
+ if key.blank? or (options.has_key?(:if) and !options[:if])
+ yield
+ else
+ begin
+ content = @controller.fragment_for(output_buffer, key, options, interpolation, &block) || ""
+ rescue MemCache::MemCacheError => err
+ content = ""
+ end
+
+ interpolation.keys.each{|k| content.gsub!(k.to_s, interpolation[k].to_s)}
+ content
+ end
+ end
+ end
+ end
+end
+
+module ActionController
+ module Caching
+ module Fragments
+ # Called by CacheHelper#cache
+ def fragment_for(buffer, name={}, options=nil, interpolation={}, &block)
+ unless (perform_caching && cache_store) then
+ content = block.call
+ interpolation.keys.each{|k| content.gsub!(k.to_s,interpolation[k].to_s)}
+ content
+ return
+ end
+
+ if cache = read_fragment(name, options)
+ buffer.concat(cache)
+ else
+ pos = buffer.length
+ block.call
+ write_fragment(name, buffer[pos..-1], options)
+ interpolation.keys.each{|k|
+ buffer[pos..-1] = buffer[pos..-1].gsub(k.to_s,interpolation[k].to_s) if buffer[pos..-1].include?(k.to_s)
+ }
+ buffer[pos..-1]
+ end
+ end
+ end
+ end
+end
+
+class MemCache
+ # The read and write methods are required to get fragment caching to
+ # work with the Robot Co-op memcache_client code.
+ # http://rubyforge.org/projects/rctools/
+ #
+ # Lifted shamelessly from Yan Pritzker's memcache_fragments plugin.
+ # This should really go back into the memcache_client core.
+ # http://skwpspace.com/2006/08/19/rails-fragment-cache-with-memcached-client-and-time-based-expire-option/
+ def read(key, options=nil)
+ options ||= {}
+ common_key = options[:common_key]
+ cache = options[:cache] || self
+ if common_key
+ cached_data = self.get_multi(key, common_key) || {}
+ Zvents::CommonKeyCache._get_value(cache, key, common_key, cached_data)
+ else
+ cache.get(key, options[:raw] || false)
+ end
+ end
+
+ def write(key,content,options=nil)
+ options ||= {}
+ cache = options[:cache] || self
+ expiry = options && options[:expire] || 0
+ common_key = options[:common_key]
+ if common_key
+ Zvents::CommonKeyCache._set(cache, key, common_key, content, expiry)
+ else
+ cache.set(key, content, expiry, options[:raw] || false)
+ end
+ end
+end
+
+# ActionController::Base.send :include, ActionController::Caching::ExtendedFragments
Added: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/pkg/extended_fragment_cache-0.3.0.gem
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/pkg/extended_fragment_cache-0.3.0.gem?rev=754694&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/olio/webapp/rails/branches/caching/vendor/plugins/extended_fragment_cache/pkg/extended_fragment_cache-0.3.0.gem
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream