【发布时间】:2014-02-11 09:37:20
【问题描述】:
在 sprockets 中,我如何检测资产是否过时?
我尝试了以下方法,结果出乎意料:
e = Rails.application.assets # sprockets env
x = Rails.application.assets.index
e['path/to/my/asset'].body
#=> prints asset
e['path/to/my/asset'].fresh?(x)
#=> true
# modify the asset file (to change mtime and digest)
e['path/to/my/asset'].fresh?(x)
#=> true
#!? Why wasn't that false?
缓存机制让我感到困惑。此外,在检查资产时,它告诉我mtime 是原始值,而不是我修改上面文件的时间。有人可以解释这里发生了什么以及我如何检测陈旧资产吗?我希望在我的 gem 中利用 sprockets 依赖/缓存系统。
我的目标:
我正在创建一个 gem,它可以在管道中查找资产并从中生成一些内容。这个 gem 与 ActionView 集成,它通过自己的缓存使事情变得复杂。如果 sprockets 中的资产过时并且将在下一次提取时重新加载,我需要一些方法来破坏 ActionView 的缓存。而不是在我的 gem 中镜像 sprocket 的缓存系统,我希望只是询问 sprocket 其资产的状态——这似乎完全有可能,只要我能弄清楚发生了什么。
【问题讨论】:
标签: ruby-on-rails caching asset-pipeline sprockets