I'm reviewing the code on a project that has the following defined in the main config.php as a boolean:

cache => true

Looking at the docs this doesn't seem to be referenced anywhere. Does the config option exist in Craft 2? I'm not seeing any documentation that states it does.

I know others like cacheMethod and cacheDuration do.

1 Answer 1


I don't believe this is a valid configuration value. You will use the cache as a tag in your twig files:

{% cache %}
    {% for element in entry.hugeField %}
        {{ element.nestedAsset.first().url }}
    {% endfor %}
{% endcache %}

The cache is most effective at nested queries in matrix fields or asset fields or category fields. Do not use the cache for plain text fields or those that can be accessed in linear time.

I would just delete that line from your config.php

  • This would seem to be the case. Caching in twig is used like this throughout but this config var seems attached to nothing. Strange because in this project it uses phpdotenv and a specific env var has been created for it. Will have to double check. Thanks. Commented May 8, 2018 at 16:56
  • Good luck! AFAIK Craft doesn't have a "always-on" caching system, although a value such as that might be useful for disabling the cache globally. Commented May 8, 2018 at 16:59
  • So digging a bit deeper, it appears to be an additional customisation when using {% cache %}, example: {% cache globally using key 'someKey' if craft.config.cache %}. That's where its coming from! Mystery solved. Not standard Craft, but I guess like you said a way to toggle caching overall. Commented May 8, 2018 at 17:42
  • @JamesWhite Correct, you can define arbitrary config keys and values that you can reference elsewhere (like in a template). Probably worth linking to craftcms.stackexchange.com/questions/13382/… as well
    – Brad Bell
    Commented May 8, 2018 at 22:05

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.