0
我想使用文件的git散列作爲資產ID。 爲此,我創建了一個如下所示的初始化程序。Git hash as RAILS_ASSET_ID。在哪裏緩存?
require 'grit'
module ActionView
module Helpers
module AssetTagHelper
def rewrite_asset_path(source)
asset_id = rails_asset_id(source)
if asset_id.blank?
source
else
"/s/#{asset_id}" + source
end
end
def rails_asset_id(source)
repo = Grit::Repo.new('.')
ENV["RAILS_ASSET_ID"] ||
repo.log('master', "#{RAILS_ROOT}/public/#{source}", :max_count => 1).first.id_abbrev rescue ""
end
end
end
end
這工作正常,但我想緩存文件的散列的地方。我可以使用一個實例變量,但我不確定是否每個請求都清除了這些變量。我可以在哪裏放置它,以便在請求之後持續存在?