0

I was reading this article where the author shows how to configure both varnish and redis for Magento 2. In the first portion, he configured Varnish. In the second section, he ends up using this configuration to setup redis:

'cache' => 
  array (
    'frontend' => 
    array (
      'default' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1', 
          'port' => '6379',
          'persistent' => '',
          'database' => '0',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '1',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
        ),
      ),
      'page_cache' => 
      array (
        'backend' => 'Cm_Cache_Backend_Redis',
        'backend_options' => 
        array (
          'server' => '127.0.0.1',
          'port' => '6379',
          'persistent' => '',
          'database' => '1',
          'force_standalone' => '0',
          'connect_retries' => '1',
          'read_timeout' => '10',
          'automatic_cleaning_factor' => '0',
          'compress_data' => '0',
          'compress_tags' => '1',
          'compress_threshold' => '20480',
          'compression_lib' => 'gzip',
        ),
      ),
    ),
  ),

My question is, does the page_cache array in the above configuration overwrite Varnish? What is the difference here between "backend" cache, "page_cache", and "full page cache" (set up in the backend of Magento).

1 Answer 1

0

The cache.frontend.page_cache key in env.php configures a Full-Page Cache (typically Redis), but it doesn't "overwrite" Varnish. But it won't be used either. If you use Varnish, this cache key configuration is not applicable. It will be used when you change caching to Redis and not Varnish, in admin settings.

The cache.frontend.default key in env.php is for general cache, which includes parsed configuration files, values from configuration tables, etc. It's not a full-page cache; it caches transient data from the database which is good to be cached. This can only be cached to files or memory (Redis, etc.). For general cache, you typically choose Redis as the go-to solution: it can store values as key-pairs efficiently, and the data of general cache is usually such, so it's a perfect match.

The full-page cache setting in the administrator area in the settings is basically a toggle between which FPC backend shall be used: would it be the one defined as cache.frontend.page_cache (and as such, Redis) or the one defined in http_cache_hosts (Varnish).

As far as configuring Redis for Magento 2, things are not so simple as the reference article wants you to think. At a minimum you should run each Redis cache in a separate instance. With Redis, you can configure it to store:

  1. Magento 2 sessions
  2. Magento 2 general cache
  3. Full Page Cache.

Each is advised to be stored in a separate Redis instance, and the instances will be configured with different expiration and maxmemory settings. See more for details. For example, for general cache, you'd want a Redis instance set up with a limited maxmemory:

maxmemory 4096mb
maxmemory-policy allkeys-lfu

Otherwise, things may quite easily fail, server-wise and result in out-of-memory conditions where your server requires a reboot.

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.