【发布时间】:2016-07-04 05:54:06
【问题描述】:
在我的 RoR 应用中,production.rb 有
MyApp::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.action_dispatch.show_detailed_exceptions = false
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# Callback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.3'
config.assets.prefix = "/assets-#{`git rev-parse HEAD`[0..8]}"
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.action_controller.perform_caching = true
end
问题出在服务器上,公用文件夹大小为 15GB。它包含许多名称如下的文件夹:
assets-2d947fb8a
assets-64bb1c0ee
assets-6b4777157
assets-33d9c439d
assets-e6f2c6c37
assets-cb3a9bc23
assets-f1e77e02d
每个文件夹都包含摘要图像、js、css 等。 那么,有没有办法自动删除/过期这些资产?
【问题讨论】:
-
为什么要根据git版本来命名asset文件夹?仅使用“资产”有什么问题? Rails 会在生成单个资产时自动对其进行版本控制。
-
看起来这正是问题所在。如果旧资产存在,它会使它们过期,但由于每个修订版的资产文件夹不同(HEAD 提交哈希),它变得臃肿。 (为什么?也许是缓存破坏?)
-
@Allolex Rails 假设
config.assets.prefix在不同版本之间是相同的,因此它会查找那里以清除旧文件,并检查是否需要生成任何文件。现在 rails 在目录中看不到任何东西,因此每次提交和运行时都会重新生成每个单一资产rake assets:precompile -
@shelvacu。是的,这是正确的(以及我所说的“变得臃肿”的意思)。 ;)
标签: ruby-on-rails ruby caching server asset-pipeline