I would like to set some functionality in a module only on if caching is turned off.

Is there a way to check in code if caching is on or off?

  • 1
    I'm guessing you mean the regular "cache pages for anonymous users", but there can be many types of caching. Please specify.
    – Letharion
    Commented Mar 4, 2012 at 10:18
  • I mean the check box "Cache pages for anonymous users" on /admin/config/development/performance.
    – cateye
    Commented Mar 4, 2012 at 10:33

1 Answer 1


The "Cache pages for anonymous users" setting is stored in the variable table (as a 0 or 1), you can get it like this:

if (variable_get('cache', 0)) {
  // Cache is turned on

If you're interested in the "Cache blocks" setting it's also in the variables table and you can get it like this:

if (variable_get('block_cache', 0)) {
  // Block cache is turned on

Just for reference the first is defined in system_performance_settings() and the second in block_form_system_performance_settings_alter().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.