在开发中禁用链轮资产缓存 [英] Disable Sprockets asset caching in development

查看:27
本文介绍了在开发中禁用链轮资产缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Rails 3.2.13 和 Rails Asset Pipeline.我想使用资产管道,以便我可以对我的资产使用 SASS、CoffeeScript 和 ERB,并让管道自动编译它们,因此我无法在开发中关闭管道.我从来没有在开发中预编译资产,甚至没有 public/assets/ 目录.

但是,当我对包含的文件进行更改时,例如对包含(渲染)在 layout.html.erb_partial.html.erb 文件> 文件,而不更改文件本身(在此示例中为 layout.html.erb),Sprockets 不会检测到更改并使缓存无效,因此我不断获得相同的陈旧文件.当我在积极的开发中这样做时,我想禁用任何资产缓存,以便我可以获得每个请求的更改,但我不知道如何做到这一点.我在 development.rb 中设置了以下所有内容:

config.action_controller.perform_caching = falseconfig.action_dispatch.rack_cache = nilconfig.middleware.delete Rack::Cacheconfig.assets.debug = trueconfig.assets.compress = falseconfig.cache_classes = false

尽管如此,文件仍会显示在 tmp/cache/assets/tmp/cache/sass/ 下,并且将来的请求无法进行更改.现在,每次我想看到更改时,我都必须手动删除这些目录.

遗憾的是,资产管道的 RoR 指南的缓存工作原理部分的全部内容是:><块引用>

Sprockets 使用默认的 Rails 缓存存储来缓存资源开发生产.

待办事项:添加有关更改默认商店的更多信息.

那么,如何让 Sprockets 按需编译资产但不缓存结果?

解决方案

这是魔法咒语:

config.assets.cache_store = :null_store # 禁用资产缓存config.sass.cache = false # 禁用 SASS 编译器缓存

资产管道有它自己的缓存实例,设置 config.assets.cache = false 什么都不做,所以你必须将它的缓存设置为 null_store禁用它.

即便如此,SASS 编译器也有自己的缓存,如果你需要禁用它,你必须单独禁用它.

I'm using Rails 3.2.13 and the Rails Asset Pipeline. I want to use the Asset Pipeline so I can use SASS and CoffeeScript and ERB for my assets and have the Pipeline automatically compile them, so I cannot turn off the pipeline in development. I am not precompiling assets in development ever and there is not even a public/assets/ directory.

However, when I make changes to an included file, such as to a _partial.html.erb file that is included (rendered) in a layout.html.erb file, without changing the file doing the including itself (in this example layout.html.erb), Sprockets doesn't detect the change and invalidate the cache, so I keep getting the same stale file. When I'm doing this in active development, I want to disable any caching of assets so I can get the changes on every request but I cannot figure out how to do this. I have set all of the following in my development.rb:

config.action_controller.perform_caching = false
config.action_dispatch.rack_cache =  nil
config.middleware.delete Rack::Cache
config.assets.debug = true
config.assets.compress = false
config.cache_classes = false

Still, even with this, files show up under tmp/cache/assets/ and tmp/cache/sass/ and changes are not available on future requests. Right now I have to manually delete those directories every time I want to see a change.

Unfortunately, the entire contents of the How Caching Works section of the RoR Guide for the Asset Pipeline is:

Sprockets uses the default Rails cache store to cache assets in development and production.

TODO: Add more about changing the default store.

So, how can I get Sprockets to compile assets on demand but not cache the results?

解决方案

Here's the magic incantation:

config.assets.cache_store = :null_store  # Disables the Asset cache
config.sass.cache = false  # Disable the SASS compiler cache

The asset pipeline has it's own instance of a cache and setting config.assets.cache = false does nothing, so you have to set its cache to be the null_store to disable it.

Even then, the SASS compiler has it's own cache, and if you need to disable it, you have to disable it separately.

这篇关于在开发中禁用链轮资产缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆