diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-24 06:25:13 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-09-24 06:25:13 +0000 |
commit | 38454983b48a117737bcd25d3962e2578d6c38f0 (patch) | |
tree | cd4accc24f7c976a46cf849c63d0f73808b8559c | |
parent | e711d8fade2a47e4a709fa3eb4b8dd7af6f6ac08 (diff) | |
download | rails-38454983b48a117737bcd25d3962e2578d6c38f0.tar.gz rails-38454983b48a117737bcd25d3962e2578d6c38f0.tar.bz2 rails-38454983b48a117737bcd25d3962e2578d6c38f0.zip |
Cache asset ids.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7607 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index e4e717c238..a1173568d8 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Cache asset ids. [Jeremy Kemper] + * Optimized named routes respect AbstractRequest.relative_url_root. #9612 [danielmorrison, Jeremy Kemper] * Introduce ActionController::Base.rescue_from to declare exception-handling methods. Cleaner style than the case-heavy rescue_action_in_public. #9449 [norbert] diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 9e38b4a714..4742b54eb9 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -409,9 +409,18 @@ module ActionView # Use the RAILS_ASSET_ID environment variable or the source's # modification time as its cache-busting asset id. def rails_asset_id(source) - ENV["RAILS_ASSET_ID"] || - File.mtime(File.join(ASSETS_DIR, source)).to_i.to_s rescue "" + if asset_id = ENV["RAILS_ASSET_ID"] + asset_id + else + @@asset_id_cache[source] ||= + if File.exist?(path = File.join(ASSETS_DIR, source)) + File.mtime(path).to_i.to_s + else + '' + end + end end + @@asset_id_cache = {} # Break out the asset path rewrite so you wish to put the asset id # someplace other than the query string. @@ -451,4 +460,4 @@ module ActionView end end end -end
\ No newline at end of file +end |