> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slm.m1amdocs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Set Up Local Data Cache of Products to Display on Your Online Storefront

Your online storefront must maintain a local cache of products and billing plans to display to the subscriber during the checkout process. To support this functionality, you must use the Subscribe APIs.

* **Use Case:** 2-2-01
* **Completed By:** Software Developer
* **Estimated Completion Time:** \<5 days

## Basic Scenario

1. Establish a local data cache of the product catalog (Products, Billing Plans and Campaigns).
2. Create an API to enable easy access to the local cache for your storefront.
3. Set a trigger mechanism or scheduled task to update the local data cache.

## Design Approach

You must set up a local cache for the product catalog. The cache displays products with pricing, currency, and terms during the subscriber checkout process. To regularly update the local cache, use the Subscribe REST endpoints to get the Products, Billing Plans and Campaigns, as shown in the following diagram.

<img src="https://mintcdn.com/amdocs-slm/ifa3y22T11JlqvtT/portal/vindiciaSubscribeAndNewRetain/subscribeUseCases/images/2201_displayProductOffers.png?fit=max&auto=format&n=ifa3y22T11JlqvtT&q=85&s=7ede5e92a79f1a04ad055ac5fb5b85b5" alt="" width="676" height="371" data-path="portal/vindiciaSubscribeAndNewRetain/subscribeUseCases/images/2201_displayProductOffers.png" />

The local cache avoids the latency caused by retrieving data directly from Subscribe during checkout.

**Note:**

* The matrix of Products and Billing Plans is your sole responsibility as the merchant. Subscribe does not enforce associations between Products and Billing Plans.

* Even if your initial Product and Billing Plan offerings are limited, the local caching procedure allows for future expansion of offerings without impacting the subscriber checkout experience.

* **[Populate Your Local Data Cache Using Subscribe APIs](../topics/2201_r_displayProductOffers#)**

* **[Example: Implementing a Product Catalog Cache with AWS](../topics/2201_r_displayProductOffers#)**

**Parent topic:**[Key Concepts and Best Practices](../topics/r_keyConceptsBestPractices)

## Populate Your Local Data Cache Using Subscribe APIs

1. Create a scheduled task that calls the products endpoint to update the local cache.

   Product REST endpoint (staging):

   `GET https://api.staging.us-west.vindicia.com/products`

   **Sample Code:**

   [Calling the products endpoint for all products](https://github.com/Vindicia/CashBoxRESTCodeSamples/blob/master/Product/Product_fetchAll.txt)

   Vindicia recommends that you refresh the cache at least once every 24 hours to catch any changes to the products. Set the limit to 10 to return ten results per page.

2. Create a scheduled task that calls the billing\_plans endpoint to update the local cache.

   Billing\_plans REST endpoint (staging):

   `GET https://api.staging.us-west.vindicia.com/billing_plans`

   **Sample Code:**

   [Calling the billing\_plans endpoint](https://github.com/Vindicia/CashBoxRESTCodeSamples/blob/master/BillingPlan/BillingPlan_fetchAll.txt)

   Vindicia recommends that you refresh the cache at least once every 24 hours to catch any changes to the billing plans. Set the limit to 10 to return ten results per page.

3. Create a scheduled task that calls the campaigns endpoint and establishes a local cache.

   Campaigns REST endpoint (staging):

   `GET https://api.staging.us-west.vindicia.com/campaigns`

   Vindicia recommends that you refresh the cache at least once every 24 hours to catch any changes to the campaigns. Set the limit to 10 to return ten results per page.

   **Note:** Increase the limit attributes if necessary to manage a higher volume of results.

4. Create a scheduled task to refresh the cache, or provide a mechanism to trigger a rebuild of the cache.

5. Create an API to access the cache contents from your storefront.

6. Enable Subscribe administrative users to update the local cache on demand when modifications to the product catalog are made.

**Parent topic:**[Set Up Local Data Cache of Products to Display on Your Online Storefront](../topics/2201_r_displayProductOffers#)

## Example: Implementing a Product Catalog Cache with AWS

This example describes how to set up a working product cache using Amazon Web Services (AWS) and how to use REST APIs to instantiate and update the cache. REST APIs access products, billing plans and campaigns from the cache for display on your storefront. The basic scenario is as follows:

1. Establish a data cache of the Vindicia Subscribe product catalog in the cloud utilizing AWS technology.
2. Create a scheduled task to retrieve the Products, Billing Plans and Campaigns to update the local data cache.

Even if your initial product, billing plan and campaign offerings are limited, the local caching procedure allows for future expansion of offerings without impacting the customer checkout experience.

### Design Approach

This use case requires your own merchant instance of AWS for deploying REST APIs and Python Lambda functions. The design approach is as follows:

1. Deploy the REST APIs on the AWS API Gateway.

2. Deploy the corresponding Lambda functions using AWS Lambda to implement the logic for the REST API.

3. Use the createProductCache, createBillingPlanCache, and createCampaignCache REST APIs to establish regularly updated local caches of products, billing plans and campaigns in AWS DynamoDB.

4. Use the local caches to display your service offerings with pricing, currency, and terms during the customer checkout process.

   Using a local cache avoids the latency caused by fetching this data directly from Vindicia Subscribe during checkout.

5. Use the fetchById, fetchByMetaData, fetchProductsByCampaignId REST APIs to access the product catalog cache contents.

6. Enable a Vindicia Subscribe administrative user to update the local caches on demand when adding a new product, billing plan or campaign. This can be accomplished by refreshing the cache regularly.

   Vindicia's best practice is to refresh the caches every 24 hours. However, AWS charges based on data throughput so it is optimal financially for you to only trigger a cache update when your product catalog has changed.

   **Note:**

   The matrix of products, billing plans and campaigns is your sole responsibility as the merchant. Vindicia Subscribe does not enforce associations between products and billing plans. Vindicia Subscribe does enforce which products and billing plans can be used with specific campaigns.

<img src="https://mintcdn.com/amdocs-slm/ifa3y22T11JlqvtT/portal/vindiciaSubscribeAndNewRetain/subscribeUseCases/images/2101_AWSCloudProductCacheExample.png?fit=max&auto=format&n=ifa3y22T11JlqvtT&q=85&s=463bb289ea7821c4bbf89fabe4afc71d" alt="" width="2480" height="1050" data-path="portal/vindiciaSubscribeAndNewRetain/subscribeUseCases/images/2101_AWSCloudProductCacheExample.png" />

| Description | Instantiates or Updates the Product Cache | |
| - | - | - |
| **Sample End Point** | [https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-product-cache](https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-product-cache) | |
| **URL Attributes** | Not Applicable | |
| **Body Attributes** | `credential` | Your Vindicia Subscribe credentials in the format `<username>:<soapPassword>`—this is the same format you use when calling Vindicia Subscribe REST APIs. |
| `environment` | A string value that can be used to segment the product catalog. This is used by the Vindicia Subscribe Anytime Demo storefront to filter the product catalog. | |
| `cacheName` | A string value that represents the name of the cache. If the cache does not already exist it is created. If the cache already exists it is updated. | |
| **Return Attributes** | `statusCode` | `200` on success. |
| `productCacheName` | Returns the name of the cache that was created or updated. | |
| `environment` | Returns the environment used in the creation or update of the cache. | |

| Description | Instantiates or Updates the Billing Plan Cache | |
| - | - | - |
| **Sample End Point** | [https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-billing-plan-cache](https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-billing-plan-cache) | |
| **URL Attributes** | Not Applicable | |
| **Body Attributes** | `credential` | Your Vindicia Subscribe credentials in the format `<username>:<soapPassword>`—this is the same format you use when calling Vindicia Subscribe REST APIs. |
| `environment` | A string value that can be used to segment the product catalog. This is used by the Vindicia Subscribe Anytime Demo storefront to filter the product catalog. | |
| `cacheName` | A string value that represents the name of the cache. If the cache does not already exist it is created. If the cache already exists it is updated. | |
| **Return Attributes** | `statusCode` | `200` on success |
| `billingPlanCacheName` | Returns the name of the cache that was created or updated. | |
| `environment` | Returns the environment used in the creation or update of the cache. | |

| Description | Instantiates or Updates the Campaign Cache | |
| - | - | - |
| **Sample End Point** | [https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-campaign-cache](https://z0i9foi7x6.execute-api.us-west-1.amazonaws.com/beta/create-campaign-cache) | |
| **URL Attributes** | Not Applicable | |
| **Body Attributes** | `credential` | Your Vindicia Subscribe credentials is the format `<username>:<soapPassword>`—this is the same format you would use when calling Vindicia Subscribe REST APIs. |
| `environment` | A string value that can be used to segment the product catalog. This is used by the Vindicia Subscribe Anytime Demo storefront to filter the product catalog. | |
| `cacheName` | A string value that represents the name of the cache. If the cache does not already exist it is created. If the cache already exists it is updated. | |
| **Return Attributes** | `statusCode` | `200` on success |
| `campaignCacheName` | Returns the name of the cache that was created or updated. | |
| `environment` | Returns the environment used in the creation or update of the cache. | |

| Description | | |
| - | - | - |
| **Sample End Point** | [https://zb67hifyq9.execute-api.us-west-1.amazonaws.com/prod/campaign/fetchproductsbycampaignid](https://zb67hifyq9.execute-api.us-west-1.amazonaws.com/prod/campaign/fetchproductsbycampaignid) | |
| **URL Attributes** | `campaignId` | The Vindicia Subscribe campaignId you are searching with |
| `environment` | The environment you wish to search. A string value that can be used to segment the product catalog. This is used by the Vindicia Subscribe Anytime Demo storefront to filter the product catalog. | |
| `cacheName` | The name of the cache you wish to search. A string value that is used to represent the name of the cache. If the cache does not already exist it is created. If the cache already exists it is updated. | |
| **Body Attributes** | Not Applicable | |
| **Return Attributes** | `statusCode` | `200` on success `400` on missing URL attributes `500` on cache does not exist |
| `merchantProductId []` | Returns an array of merchantProductIds. | |
| `environment` | Returns the environment used in the search. | |

| Description | Returns a list of Product Objects associated with a given set of MetaData | |
| - | - | - |
| **Sample End Point** | [https://9vd0j92jya.execute-api.us-west-1.amazonaws.com/prod/product-catalog/fetchbymetadata](https://9vd0j92jya.execute-api.us-west-1.amazonaws.com/prod/product-catalog/fetchbymetadata) | |
| **URL Attributes** | `cacheName` | The Product or Billing Plan cache you wish to search. **Note:** Campaign cache does not support MetaData. |
| `environment` | The Environment you wish to search within the cache. | |
| `name` | The MetaData Name value that you are filtering on. | |
| `value` | The MetaData Value value you are filtering on. | |
| **Body Attributes** | Not Applicable | |
| **Return Attributes** | `statusCode` | `200` on success `400` on missing URL attributes `500` on cache does not exist |
| `response` | Returns an array of Products or BillingPlans matching the search parameters. | |
| `cacheName` | Returns the cacheName used in the search. | |
| `environment` | Returns the environment used in the search. | |

| Description | Returns a list of (Product, Billing Plan or Campaign) Objects associated with a given id | |
| - | - | - |
| **Sample End Point** | [https://v1g95ni3pg.execute-api.us-west-1.amazonaws.com/prod/product-catalog/fetchbyid](https://v1g95ni3pg.execute-api.us-west-1.amazonaws.com/prod/product-catalog/fetchbyid) | |
| **URL Attributes** | `cacheName` | The Product, Billing Plan or Campaign cache you wish to search |
| `environment` | The Environment you wish to search within the cache | |
| `id` | The id value that you are filtering on | |
| `type` | enumerated values: product, billingPlan or campaign | |
| **Body Attributes** | Not Applicable | |
| **Return Attributes** | `statusCode` | `200` on success `400` on missing URL attributes `500` on cache does not exist |
| `response` | Returns an object of Product or BillingPlan or Campaign matching the search parameters | |
| `cacheName` | Returns the cacheName used in the search | |
| `environment` | Returns the environment used in the search | |

### Sample Code

The following table contains a list of reusable assets. Reusable assets are sample code that reflect Vindicia best practices for implementation of the given use case.

**Note:**

**Disclaimer**

Reusable assets are provided as-is and are not supported by Vindicia. Reusable assets are used “at will” by the merchant. You as the merchant are responsible for support of any reusable asset you incorporate into your solution.

The VTL files are for use as JSON Body Mapping Templates for the Integration Request configuration in the REST API's that you set up in the AWS API Gateway. The Python code is used within the Lambda function that you associate to each API.

| Asset Name | Source Destination | Source Language | Link |
| - | - | - | - |
| `createProductCache` | Lambda | Python 2.7 | [https://github.com/Vindicia/CB4-Code-Repository/tree/master/CB4-2-001](https://github.com/Vindicia/CB4-Code-Repository/tree/master/CB4-2-001) |
| `createProductCache` | API Gateway | VTL | |
| `createBillingPlanCache` | Lambda | Python 2.7 | |
| `createBillingPlanCache` | API Gateway | VTL | |
| `createCampaignCache` | Lambda | Python 2.7 | |
| `createCampaignCache` | API Gateway | VTL | |
| `fetchProductsByCampaignId` | Lambda | Python 2.7 | |
| `fetchProductsByCampaignId` | API Gateway | VTL | |
| `fetchByMetaData` | Lambda | Python 2.7 | |
| `fetchByMetaData` | API Gateway | VTL | |
| `fetchById` | Lambda | Python 2.7 | |
| `fetchById` | API Gateway | VTL | |
| **Parent topic:**[Set Up Local Data Cache of Products to Display on Your Online Storefront](../topics/2201_r_displayProductOffers#) | | | |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.