Skip to main content
Version: next

Caching strategies

Learn about the caching strategies available in Front-Commerce's Magento 1 extension, and how to configure them for optimal.

PerMagentoCustomerGroup

The PerMagentoCustomerGroup implementation is a decorator that is specific to Magento 1 modules. It will decorate the existing caching strategies so that DataLoader keys are specific to the current customer group. We highly recommend to use it on Magento stores that have price per group, so they can leverage other caching mechanisms (such as Redis).

It is possible to provide a default group to use as scope for guest users.

Here is a configuration example:

app/config/caching.js
export default {
strategies: [
// The PerMagentoCustomerGroup strategy MUST be registered after a persistent cache implementation
// because it has no effect in the context of the default per-request in-memory caching.
{
implementation: "Redis",
supports: "*",
config: {
host: "127.0.0.1",
},
},
{
implementation: "PerMagentoCustomerGroup",
// Will scope all data from the CatalogPrice DataLoader with the customer group
// (and other relevant price data loaders)
// before they are transmitted to the previous strategy (Redis).
// Other dataLoaders will use Redis storage in a standard fashion.
supports: [
"CatalogPrice",
"CatalogProductChildrenPrice",
"CatalogProductBundlePrice",
],
config: {
defaultGroupId: 0,
},
},
],
};

PerMagentoCustomerTaxZone

The PerMagentoCustomerTaxZone implementation is a decorator that is specific to the Magento platform. It will decorate the existing caching strategies so that DataLoader keys are specific to the current customer's tax zone. We highly recommend to use it on Magento stores that have price with taxes depending on several tax zones, so they can leverage other caching mechanisms (such as Redis).

As this strategy can be complex, the tax zone definition is left to the integrator through the taxZoneKeyFromAddress function

Here is a configuration example:

app/config/caching.js
export default {
strategies: [
// The PerMagentoCustomerTaxZone strategy MUST be registered after a persistent cache implementation
// because it has no effect in the context of the default per-request in-memory caching.
{
implementation: "Redis",
supports: "*",
config: {
host: "127.0.0.1",
},
},
{
implementation: "PerMagentoCustomerTaxZone",
supports: [
"CatalogPrice",
"CatalogProductChildrenPrice",
"CatalogProductBundlePrice",
],
config: {
addressType: "shipping", // or "billing" depending on which address is used to define the taxes showed to the user
defaultTaxZoneKey: "FR",
// Uncomment this line to override the default tax zone partitioning
// taxZoneKeyFromAddress: (address) => {
// // see https://docs.magento.com/user-guide/tax/tax-zones-rates.html
// return address.country_id;
// },
},
},
],
};

PerCurrency

The PerCurrency implementation is a decorator that is specific to Magento 1 integrations. It will decorate the existing caching strategies so that DataLoader keys are different depending on the store's currency selected by the user. This is only useful if a store has multiple currencies (config/stores.js::availableCurrencies). It should be used on any DataLoader that returns a price value based on the user's session.

Here is a configuration example:

app/config/caching.js
export default {
strategies: [
// The PerCurrency strategy MUST be registered after a persistent cache implementation
// because it has no effect in the context of the default per-request in-memory caching.
{
implementation: "Redis",
supports: "*",
config: {
host: "127.0.0.1",
},
},
{
implementation: "PerCurrency",
supports: [
"CatalogPrice",
"CatalogProductChildrenPrice",
"CatalogProductBundlePrice", // only for Magento 2
"CatalogProductBundle", // only for Magento 1
],
},
],
};