@scayle/storefront-core 7.32.0 → 7.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scayle/storefront-core
2
2
 
3
+ ## 7.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Previously the caching time for product RPCs was one hour which could easily lead to outdated product information for a long time.
8
+
9
+ The `getProductById` and `getProductsByIds` RPCs are now cached for 5 Minutes and `getProductsByCategory` is now cached for 15 Minutes.
10
+
3
11
  ## 7.32.0
4
12
 
5
13
  ### Minor Changes
@@ -3,11 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Cached = void 0;
6
+ exports.MINUTE = exports.Cached = void 0;
7
7
  var _autobind = require("../helpers/autobind.cjs");
8
8
  var _utils = require("../utils/index.cjs");
9
9
  var _hash = require("../utils/hash.cjs");
10
10
  var _constants = require("../constants/index.cjs");
11
+ const MINUTE = exports.MINUTE = 60;
11
12
  const CACHE_NOT_INITIALIZED_MSG = "Cache is not initialized";
12
13
  class Cached {
13
14
  cache;
@@ -66,7 +67,7 @@ class Cached {
66
67
  if (!this.isCacheEnabled) {
67
68
  return;
68
69
  }
69
- const ttl = options?.ttl || 60 * 60;
70
+ const ttl = options?.ttl || 60 * MINUTE;
70
71
  if (ttl) {
71
72
  await (0, _utils.timeout)(_constants.CACHE_TIMEOUT, this.cache.set(cacheKey, value, ttl));
72
73
  }
@@ -1,5 +1,6 @@
1
1
  import { Log } from '../utils';
2
2
  import { Cache as CacheInterface } from './cache';
3
+ export declare const MINUTE = 60;
3
4
  export type CacheOptions = Partial<{
4
5
  ttl: number;
5
6
  cacheKey: string;
@@ -2,6 +2,7 @@ import { autobind } from "../helpers/autobind.mjs";
2
2
  import { timeout } from "../utils/index.mjs";
3
3
  import { sha256 } from "../utils/hash.mjs";
4
4
  import { CACHE_TIMEOUT } from "../constants/index.mjs";
5
+ export const MINUTE = 60;
5
6
  const CACHE_NOT_INITIALIZED_MSG = "Cache is not initialized";
6
7
  export class Cached {
7
8
  cache;
@@ -63,7 +64,7 @@ export class Cached {
63
64
  if (!this.isCacheEnabled) {
64
65
  return;
65
66
  }
66
- const ttl = options?.ttl || 60 * 60;
67
+ const ttl = options?.ttl || 60 * MINUTE;
67
68
  if (ttl) {
68
69
  await timeout(CACHE_TIMEOUT, this.cache.set(cacheKey, value, ttl));
69
70
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getProductsCount = exports.getProductsByIds = exports.getProductsByCategory = exports.getProductById = exports.getFilters = exports.fetchAllFiltersForCategory = void 0;
7
7
  var _helpers = require("../../helpers/index.cjs");
8
8
  var _constants = require("../../constants/index.cjs");
9
+ var _cache = require("../../cache/index.cjs");
9
10
  const MAX_PER_PAGE = 100;
10
11
  const getProductById = exports.getProductById = async function getProductById2(options, {
11
12
  bapiClient,
@@ -14,7 +15,8 @@ const getProductById = exports.getProductById = async function getProductById2(o
14
15
  withParams
15
16
  }) {
16
17
  return await cached(bapiClient.products.getById, {
17
- cacheKeyPrefix: `getById-product-${options.id}`
18
+ cacheKeyPrefix: `getById-product-${options.id}`,
19
+ ttl: 5 * _cache.MINUTE
18
20
  })(options.id, {
19
21
  with: options.with ?? withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
20
22
  campaignKey,
@@ -29,7 +31,8 @@ const getProductsByIds = exports.getProductsByIds = async function getProductsBy
29
31
  withParams
30
32
  }) {
31
33
  return await cached(bapiClient.products.getByIds, {
32
- cacheKeyPrefix: "getByIds-products"
34
+ cacheKeyPrefix: "getByIds-products",
35
+ ttl: 5 * _cache.MINUTE
33
36
  })(options.ids, {
34
37
  with: options.with ?? withParams?.product ?? _constants.MIN_WITH_PARAMS_PRODUCT,
35
38
  campaignKey,
@@ -74,6 +77,7 @@ const getProductsByCategory = exports.getProductsByCategory = async function get
74
77
  pagination
75
78
  } = await cached(bapiClient.products.query, {
76
79
  ...cache,
80
+ ttl: 15 * _cache.MINUTE,
77
81
  cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
78
82
  })({
79
83
  where: {
@@ -155,6 +159,7 @@ const getFilters = exports.getFilters = async function getFilters2({
155
159
  including: includedFilters,
156
160
  orFiltersOperator
157
161
  }), cached(bapiClient.products.query, {
162
+ ttl: 15 * _cache.MINUTE,
158
163
  cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
159
164
  })({
160
165
  where: {
@@ -220,6 +225,7 @@ const getProductsCount = exports.getProductsCount = async function getProductsCo
220
225
  })(sanitizedPath);
221
226
  }
222
227
  const productCount = await cached(bapiClient.products.query, {
228
+ ttl: 15 * _cache.MINUTE,
223
229
  cacheKeyPrefix: "products-query"
224
230
  })({
225
231
  where: {
@@ -1,9 +1,11 @@
1
1
  import { splitAndRemoveEmpty } from "../../helpers/index.mjs";
2
2
  import { MIN_WITH_PARAMS_PRODUCT } from "../../constants/index.mjs";
3
+ import { MINUTE } from "../../cache/index.mjs";
3
4
  const MAX_PER_PAGE = 100;
4
5
  export const getProductById = async function getProductById2(options, { bapiClient, cached, campaignKey, withParams }) {
5
6
  return await cached(bapiClient.products.getById, {
6
- cacheKeyPrefix: `getById-product-${options.id}`
7
+ cacheKeyPrefix: `getById-product-${options.id}`,
8
+ ttl: 5 * MINUTE
7
9
  })(options.id, {
8
10
  with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
9
11
  campaignKey,
@@ -13,7 +15,8 @@ export const getProductById = async function getProductById2(options, { bapiClie
13
15
  };
14
16
  export const getProductsByIds = async function getProductsByIds2(options, { bapiClient, cached, campaignKey, withParams }) {
15
17
  return await cached(bapiClient.products.getByIds, {
16
- cacheKeyPrefix: "getByIds-products"
18
+ cacheKeyPrefix: "getByIds-products",
19
+ ttl: 5 * MINUTE
17
20
  })(options.ids, {
18
21
  with: options.with ?? withParams?.product ?? MIN_WITH_PARAMS_PRODUCT,
19
22
  campaignKey,
@@ -49,6 +52,7 @@ export const getProductsByCategory = async function getProductsByCategory2({
49
52
  bapiClient.products.query,
50
53
  {
51
54
  ...cache,
55
+ ttl: 15 * MINUTE,
52
56
  cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
53
57
  }
54
58
  )({
@@ -128,6 +132,7 @@ export const getFilters = async function getFilters2({
128
132
  orFiltersOperator
129
133
  }),
130
134
  cached(bapiClient.products.query, {
135
+ ttl: 15 * MINUTE,
131
136
  cacheKeyPrefix: `products-query-category-${category === "/" ? "root" : category}`
132
137
  })({
133
138
  where: {
@@ -184,6 +189,7 @@ export const getProductsCount = async function getProductsCount2({
184
189
  })(sanitizedPath);
185
190
  }
186
191
  const productCount = await cached(bapiClient.products.query, {
192
+ ttl: 15 * MINUTE,
187
193
  cacheKeyPrefix: "products-query"
188
194
  })({
189
195
  where: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-core",
3
- "version": "7.32.0",
3
+ "version": "7.33.0",
4
4
  "description": "Collection of essential utilities to work with the Storefront API",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",