diff --git a/packages/core/src/base/staticClient.ts b/packages/core/src/base/staticClient.ts index a3e17042..3da365ae 100644 --- a/packages/core/src/base/staticClient.ts +++ b/packages/core/src/base/staticClient.ts @@ -114,6 +114,7 @@ async function runFetch( fetchOptions.headers["Content-Type"] = CONTENT_TYPE; } + // To disable response caching, set cacheManager to null if (options.client.clientConfig.cacheManager) { fetchOptions.cacheManager = options.client.clientConfig.cacheManager; } diff --git a/packages/generator/README.md b/packages/generator/README.md index 634f48b1..f11acfbb 100644 --- a/packages/generator/README.md +++ b/packages/generator/README.md @@ -36,15 +36,16 @@ To use an SDK client, instantiate an object of that client and configure these p * APIs. */ ​ -// Import the SDK in TypeScript or newer versions of Node.js -import CommerceSdk from "commerce-sdk"; +// Import the SDK in TypeScript +import * as CommerceSdk from "commerce-sdk"; +// For Javascript, use: +// import as CommerceSdk from "commerce-sdk"; const { ClientConfig, helpers, Search } = CommerceSdk; - // Older Node.js versions can instead use: // const { ClientConfig, helpers, Search } = require("commerce-sdk"); // Create a configuration to use when creating API clients -// In TypeScript, this can be specified as const config:ClientConfig +// In TypeScript, let config = new ClientConfig(); const config = { headers: { connection: "close" @@ -93,6 +94,30 @@ helpers.getShopperToken(config, { type: "guest" }).then(async (token) => { }); ``` +## Caching + +In-memory caching of responses is enabled by default. This implementation respects [standard cache headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control). To disable caching for a client, set cacheManager to 'null'. + + + +### Sample Code +```javascript +const config = { + cacheManager: null, + headers: { + connection: "close" + }, + parameters: { + clientId: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + organizationId: "f_ecom_bblx_stg", + shortCode: "0dnz6oep", + siteId: "RefArch" + } +} +``` + + + When using an IDE such as VSCode, the autocomplete feature lets you view the available method and class definitions, including parameters. ​