Permalink
Browse files

The plugin functionality can now be done using the Rails core. Deprec…

…ate the plugin.
  • Loading branch information...
1 parent 2b345f5 commit 2538d2e50e203e2dac02d2addc29d8df8c822340 @craigw committed Apr 3, 2010
Showing with 19 additions and 1 deletion.
  1. +8 −0 README
  2. +11 −1 lib/cached_asset_names.rb
View
8 README
@@ -1,6 +1,14 @@
CachedAssetNames
================
+==============================================================================
+THE FUNCTIONALITY OF THIS PLUGIN HAS BEEN ADDED TO RAILS CORE. THE PLUGIN IS
+NOW DEPRECATED AND IS ONLY AVAILABLE AS A HISTORIC INTEREST.
+
+SEE THIS COMMIT TO RAILS FOR THE PREFERRED WAY OF SETTING THE ASSET PATH TO
+MAKE IT MORE CACHE-FRIENDLY: http://github.com/rails/rails/commit/49bc6a249e2a200216f8a96c36093a2c7a471c9b
+==============================================================================
+
Caching is King as they say, but if you cache your static assets and deploy
new versions of them then some proxy servers such as Squid won't be able to
use Rails built-in cache busting to detect new versions.
View
@@ -1,6 +1,9 @@
if ActionController::Base.perform_caching
ActionView::Helpers::AssetTagHelper.class_eval do
def rewrite_asset_path(source)
+ RAILS_DEFAULT_LOGGER.warn "The cached_asset_names plugin " +
+ "functionality has been included in Rails. " +
+ "The plugin is now deprecated."
asset_id = rails_asset_id(source)
if asset_id.blank?
source
@@ -30,6 +33,13 @@ def pre_cache_busting_filename(path)
end
end
+ def build_number
+ # Ideally you should set this to the build number of your deployment to
+ # get consistent versions across all of your application servers, but
+ # we need to provide a default just in case.
+ @@build_number ||= Time.now.to_i
+ end
+
def write_asset_file_contents_with_cached_asset_names(asset_file_path, asset_paths)
write_asset_file_contents_without_cached_asset_names(asset_file_path, asset_paths)
if asset_file_path =~ /\.css$/
@@ -39,7 +49,7 @@ def write_asset_file_contents_with_cached_asset_names(asset_file_path, asset_pat
uri = line.scan(/url\((\'?\/images\/.*\'?)\)/).to_a[0].to_a[0]
destination_parts = uri.split(/\./)
file_ext = destination_parts.pop
- destination_parts[-1] += "-v#{BUILD_NUMBER}"
+ destination_parts[-1] += "-v#{build_number}"
destination_parts.push file_ext
destination = destination_parts.join('.')
RAILS_DEFAULT_LOGGER.info "[cache] Rewriting #{uri} to cached url #{destination} in #{asset_file_path}"

0 comments on commit 2538d2e

Please sign in to comment.