diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-01-05 01:10:55 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-01-05 01:10:55 -0800 |
commit | db619c4a4115d5eeca9473f8f77f34c877e4e1dd (patch) | |
tree | 18c86d54f27884f5f03db0eba86665d4563cfa7e /actionpack/lib/action_view | |
parent | ca54cc5df72a8bd7660d5be8333dcee2b6949257 (diff) | |
download | rails-db619c4a4115d5eeca9473f8f77f34c877e4e1dd.tar.gz rails-db619c4a4115d5eeca9473f8f77f34c877e4e1dd.tar.bz2 rails-db619c4a4115d5eeca9473f8f77f34c877e4e1dd.zip |
Sync 'rails/rails/master'
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/asset_tag_helper.rb | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index a341b453ec..58f8cca6be 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -468,6 +468,22 @@ module ActionView tag("img", options) end + def self.cache_asset_timestamps + @@cache_asset_timestamps + end + + # You can enable or disable the asset tag timestamps cache. + # With the cache enabled, the asset tag helper methods will make fewer + # expense file system calls. However this prevents you from modifying + # any asset files while the server is running. + # + # ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false + def self.cache_asset_timestamps=(value) + @@cache_asset_timestamps = value + end + + @@cache_asset_timestamps = true + private # Add the the extension +ext+ if not present. Return full URLs otherwise untouched. # Prefix with <tt>/dir/</tt> if lacking a leading +/+. Account for relative URL @@ -526,18 +542,28 @@ module ActionView end end + @@asset_timestamps_cache = {} + @@asset_timestamps_cache_guard = Mutex.new + # Use the RAILS_ASSET_ID environment variable or the source's # modification time as its cache-busting asset id. def rails_asset_id(source) if asset_id = ENV["RAILS_ASSET_ID"] asset_id else - path = File.join(ASSETS_DIR, source) - - if File.exist?(path) - File.mtime(path).to_i.to_s + if @@cache_asset_timestamps && (asset_id = @@asset_timestamps_cache[source]) + asset_id else - '' + path = File.join(ASSETS_DIR, source) + asset_id = File.exist?(path) ? File.mtime(path).to_i.to_s : '' + + if @@cache_asset_timestamps + @@asset_timestamps_cache_guard.synchronize do + @@asset_timestamps_cache[source] = asset_id + end + end + + asset_id end end end |