Skip to main content
Version: 3.x

Invalidating the cache

Invalidating the cache

For persistent caching, remote systems must invalidate the cache when necessary.

Front-Commerce provides several endpoints for it. They respond to GET or POST requests and are secured with a token to be passed in a auth-token header. The expected token must be configured with the FRONT_COMMERCE_CACHE_API_TOKEN environment variable.

POST for batched invalidations

This is the recommended way to invalidate cache. It allows to invalidate several entries in one HTTP call which is more efficient.

  • Endpoint: /_cache invalidate all data from the scopes sent in the body
  • Body: list of cache invalidation descriptor with the following object keys
    • scope: shop code (for instance one store)
    • key: loader key to invalidate
    • id: single id to invalidate for the key loader (in the given scope)

For each key of the invalidation descriptor, it is possible to define the value "all" (reserved keyword) to invalidate every defined object. See the example below.

Example
[
{ scope: "default", key: "CatalogProduct", id: "VSK12" },
{ scope: "default", key: "all", id: "VSK13" },
{ scope: "all", key: "CatalogCategory", id: "42" },
{ scope: "default", key: "CmsPage", id: "all" },
];

GET for atomic invalidations

These endpoints were the first ones implemented in Front-Commerce. They are less efficient than batching invalidations, but may be more convenient for webhooks or simple scripts.

  • /_cache: invalidate all data in persistent cache
  • /_cache/:scope: invalidate all data for a given scope (for instance one store)
  • /_cache/:scope/:key: invalidate all data of a given loader (matching :key) for a given store
  • /_cache/:scope/:key/:id: invalidate cached data for a single id of a given loader in a given store
note

Our Magento 2 and Magento 1 extensions handle cache invalidation by default, please refer to their respective documentations to learn how to add your own invalidation logic (for custom Magento entities).