Prevent resource caching 3.2.11 from caching?

I read a lot of posts and articles, questions and answers on the Rails pipeline, but I still have not figured out how to disable caching altogether.

We use Rails 3.2.11, and in our lab environment (similar to development) we have a problem, because although we do not precompile or print assets in the asset pipeline, they are still cached in Rails (Rack?). This is annoying because some of the assets are ERBs that change depending on a different configuration, so the cache becomes obsolete. To try disabling caching, we set this configuration:

config.action_controller.perform_caching = false config.assets.compress = false config.assets.debug = true # just in case config.cache_store = :file_store, "file_cache" 

However, in any case, the assets appear in tmp/cache/assets . I would at least expect them to appear in file_cache , but I really expect them to not be cached at all.

How can we prevent caching of these assets? Simply removing the cache is not enough in this environment.

Bonus question: as long as these files are cached, why are they in tmp/ and not in file_cache/ ?

+6
source share
3 answers

To disable the resource cache:

 config.assets.cache_store = :null_store 

Please note that this is config. .cache_store assets not Rails config.cache_store.

Also note that Sass has a separate cache for compiled style sheets, by default in tmp/cache/sass , and if you want to disable this, you have to do it separately:

 config.sass.cache = false 

To answer the bonus question when the Rails Guide says:

The default Rails cache will be used by Sprockets to cache assets during development and production.

I thought they meant using a configured Rails cache store. I was wrong, it uses the default cache unless you explicitly change the resource cache.

+8
source

To completely disable the resource pipeline, you can add this directive to your environment file:

 config.assets.enabled = false 

But if you still want to use compilation and asset caching for your static JS and CSS and at the same time use ERB files for dynamic assets, you can create my_assets_controller and create views for this controller that provide dynamic content (files with .css.erb extensions .css.erb and .js.erb ). You just need to include <%= javascript_path '/my_assets/things_dynamically_generated.js' %> in your view or layout file

-1
source

That sounds like an XY issue.

Principle 1: A string must be deterministic and configuration independent for the environment.

Principle 2: Compiling static assets should be part of the assembly.

You must move on to purely static assets. You can use ERB, but just to call methods like asset_path , which are deterministic and that give the same result with the same code base. You can put data or behavior based on the configuration there, but only if the data or behavior is the same in all deployments (dev, test, staging, qa, pre-prod and prod).

Everything that comes from the configuration for each environment should not be part of static assets. Instead, you can deliver this in HTTP headers, attributes of the <html> element, or other injection methods. The static asset code must be smart enough to search for the entered data in the HTTP headers or <html> attributes and change its behavior based on the data that was entered.

Regarding the bonus question, config.cache_store not a configuration control for stars, sasses, compasses, etc.

-1
source

All Articles