# SSR Cache

NOTE: Redis integration is disabled by default, toggle VSF_REDIS_ENABLED=true flag to activate connection.

In commercetools integration, we are caching some server-side rendered pages with Redis out of the box. To make use of it, you need to add the Redis configuration to the .env file in your project.

// .env
VSF_REDIS_ENABLED=false
VSF_REDIS_HOST=127.0.0.1
VSF_REDIS_PORT=6379
VSF_REDIS_PASSWORD=
VSF_REDIS_KEY_PREFIX=

VSF_REDIS_CACHE_INVALIDATE_KEY=here_is_your_unique_key_for_cache_invalidation
VSF_REDIS_CACHE_INVALIDATE_URL=/cache-invalidate

# What is cached

The pages that are cached are:

  • Home page with the Vhome tag.
  • Category page with the Vcategory tag and tags for products: P${prod._id} as well as categories C${cat.id}
  • Product page with the Vproduct-${route.value.params.id} tag and tags for the main product P${prod._id} as well as related products P${prod._id} and categories C${cat.id}

# Invalidating tags

To invalidate a tag and remove pages associated with that tag, use the Invalidation endpoint (opens new window).

Go to the route configured in the .env file under the VSF_REDIS_CACHE_INVALIDATE_URL key with two query parameters:

  • key — string matching the VSF_REDIS_CACHE_INVALIDATE_KEY key in the .env file.
  • tags — a comma-separated list of tags for invalidation.

Assuming that you are running the application locally, the VSF_REDIS_CACHE_INVALIDATE_URL key is equal to /cache-invalidate, and the VSF_REDIS_CACHE_INVALIDATE_KEY key is equal to secret_key, and you want to invalidate the Vhome tag, the full URL will look like this:

# How to cache other pages

We added caching only to the most visited pages. However, you can cache other pages as well, including custom ones. You can find detailed instructions on how to use cache on the SSR Cache (opens new window) and Redis cache (opens new window) pages.

TIP

You don't need to add any additional packages to cache more pages — just add or modify tags in components.