Skip to content

Cache configuration

NOTE: All Magento stores are required to have cache enabled on production AND use Redis for cache storage. We do not allow cache to be stored in files nor in the database. See Magento Requirements for the full list of requirements.

Magento 2

We recommend Redis, if you are using Varnish FPC in Magento 2, you do not need Redis for the page_cache. Add the below into your env.php file to enable Redis cache.

<? php
'cache' =>
array(
   'frontend' =>
   array(
      'default' =>
      array(
         'backend' => 'Cm_Cache_Backend_Redis',
         'backend_options' =>
         array(
            'server' => 'redis',
            'database' => '0',
            'port' => '6379'
            ),
    ),
    'page_cache' =>
    array(
      'backend' => 'Cm_Cache_Backend_Redis',
      'backend_options' =>
       array(
         'server' => 'redis',
         'port' => '6379',
         'database' => '1',
         'compress_data' => '1'
       )
    )
  )
),
?>

Magento 1

Add the configuration below to your local.xml file for Magento 1. The full page cache section only applies for Magento 1 EE. Check the developer document for any 3rd party FPC module. Most support Redis.

<cache>
  <backend_options>
    <server><![CDATA[redis]]></server>
    <port><![CDATA[6379]]></port>
    <persistent><![CDATA[]]></persistent>
    <database><![CDATA[2]]></database>
    <password><![CDATA[]]></password>
    <connect_retries><![CDATA[1]]></connect_retries>
    <read_timeout><![CDATA[10]]></read_timeout>
    <automatic_cleaning_factor><![CDATA[0]]></automatic_cleaning_factor>
    <compress_data><![CDATA[1]]></compress_data>
    <compress_tags><![CDATA[1]]></compress_tags>
    <compress_threshold><![CDATA[20480]]></compress_threshold>
    <compression_lib><![CDATA[gzip]]></compression_lib>
    <use_lua><![CDATA[0]]></use_lua>
<auto_expire_lifetime>604800</auto_expire_lifetime>
  </backend_options>
  <backend><![CDATA[Cm_Cache_Backend_Redis]]></backend>
</cache>

Magento 1 ADD FOR FPC ( Enterprise )

<full_page_cache>
  <backend>Cm_Cache_Backend_Redis</backend>
  <backend_options>
    <server>redis</server> <!-- or absolute path to unix socket -->
    <port>6379</port>
    <persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->
    <database>3</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases -->
    <password></password> <!-- Specify if your Redis server requires authentication -->
    <force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP -->
    <connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures -->
    <lifetimelimit>57600</lifetimelimit>    <!-- 16 hours of lifetime for cache record -->
    <compress_data>0</compress_data>        <!-- DISABLE compression for EE FPC since it already uses compression -->
    <auto_expire_lifetime>604800</auto_expire_lifetime> <!-- Force an expiry (Enterprise_PageCache will not set one) -->
    <auto_expire_refresh_on_load></auto_expire_refresh_on_load> <!-- Refresh keys when loaded (Keeps cache primed frequently requested resources) -->
  </backend_options>
</full_page_cache>

Enabling Caches

You can enable caches with the following:

Magento 1 n98-magerun cache:enable

Magento 2 n98-magerun2 cache:enable