maicher
maicher

Reputation: 2745

How to perform a check if Rails 5 cache is enabled?

In Rails 5 there is a possibility to enable/disable cache:

rails dev:cache
=> Development mode is now being cached.

rails dev:cache
=> Development mode is no longer being cached.

My question is, is there a method from which the application can get the information if the cache is enabled or disabled? Something like: Rails.cache.enabled?

I know that I can check the existence of file tmp/caching-dev.txt, however I'm looking for something higher level.

Upvotes: 3

Views: 2891

Answers (1)

Hieu Pham
Hieu Pham

Reputation: 6707

When cache is enabled, the cache_store in rails config mustn't be :null_store, so we can easily check with:

Rails.application.config.cache_store != :null_store

=> true means cache is enabled

Or we can check directly with perform_caching flag: (Thanks @AjinkyaPisal)

Rails.application.config.action_controller.perform_caching

Upvotes: 9

Related Questions