arrow-left

All pages
gitbookPowered by GitBook
1 of 4

Loading...

Loading...

Loading...

Loading...

Loading a single item from a dynamic cache key

hashtag
Introduction

This approach assumes that the cache to be loaded was added with a payload variable for the cache key, and is comprised of multiple, single-record payloads (having been through a flow control shape).

Each of these payloads has its own, unique cache key (when data was added to the cache, this key was generated dynamically by resolving a cache key payload variable).

circle-info

For more information about this stage, please see .

When we come to load this data, we must target the required cache key. If you only want a single item, the quickest way is to specify the resolved cache key.

hashtag
How it works

The shape works as normal - you choose the cache and cache key to be loaded:

However, the important point to consider is that the cache key that you specify here will have been generated dynamically by resolving the payload variable that was specified .

hashtag
Example

Consider the following process flow:

Here, our manual payload contains customer data as below:

To allow us to target specific customer records from this payload, we send it through a flow control shape, which is set to creating one payload for customer:

...so now we have lots of payloads to be cached:

If we look at the payload for the first of these, we can see it contains a single customer record - notice that there's an id field with a value of 1000000001. This field uniquely identifies each record.

Next we define an add to cache shape - we create a new cache and use a payload variable to generate a dynamic cache key for each incoming payload:

Here, they payload variable is defined as:

where:

  • customer- is static text to prefix the resolved variable.

  • [[payload.]] instructs the shape that this variable should be resolved from the incoming payload.

  • 0

So, if we take our first payload above:

...our payload variable would resolve to the following cache key:

This is what we use in our load from cache shape:

denotes that the first occurrence of the following item found in the payload should be used to resolve this variable.
  • id is the name of the field in the payload to be used to resolve this variable

  • Generating dynamic cache keys with payload variables
    load from cache
    when the cache was added
    [
        {
            "id": 1000000001,
            "first_name": "Jane",
            "last_name": "Smith",
            "items": {
               "itemref": "0000001",
                "item1": "apples",
                "item2": "oranges",
                "item3": "pears"
            }
        },
        {
            "id": 1000000002,
            "first_name": "George",
            "last_name": "Jones",
            "items": {
               "itemref": "0000002",
                "item1": "tangerines",
                "item2": "peaches",
                "item3": "grapes"
            }
        },
        {
            "id": 1000000003,
            "first_name": "Bob",
            "last_name": "Brown",
            "items": {
               "itemref": "0000003",
                "item1": "nectarines",
                "item2": "raspberries",
                "item3": "strawberries"
            }
        },
        {
            "id": 1000000004,
            "first_name": "Marjorie",
            "last_name": "Simpson",
            "items": {
               "itemref": "0000004",
                "item1": "blueberries",
                "item2": "cranberries",
                "item3": "apricots"
            }
        }
    ]
    customer-[[payload.0.id]]
    customer-1000000001

    Loading all cached data from a static cache key

    hashtag
    Introduction

    This approach is the simplest - all incoming data is cached with a static cache key.

    hashtag
    How it works

    In the example below, all incoming customer records will be added to a cache named ALLcustomers and a static cache key named customers:

    When the data is cached, it's likely that the cache will include multiple records - for example:

    To retrieve this cache, we simply drop a load from cache shape where required in the process flow and specify the same cache and cache key that were defined in the corresponding add to cache shape:

    hashtag
    Load a single, targeted item from a dynamic cache key

    This approach assumes The shape works as normal to retrieve cached data where the cache was created with a payload variable - you choose the cache name and key to be loaded:

    However, the important point to consider is that the cache key that you specify here will have been generated from the payload variable that was specified when the cache was created.

    If a payload variable has been used to cache data, you would typically have included a to create multiple payloads - for example:

    So you will have multiple cache keys that can be loaded. To do this, you can add one shape for every cache key that you want to retrieve, specifying the required key in each case. For example:

    Alternatively, you can add a single shape and target specific cache keys by passing in the required ids.

    hashtag
    Load multiple, targeted items from a dynamic cache key

    load from cache
    flow control shape
    load from cache
    load from cache

    What cached data do you want to load?

    hashtag
    Introduction

    Loading data from a cache is very straightforward using the load from cache shape, however you do need to consider what data you want to load. You can:

    Each of these options requires a slightly different approach, as summarised in the diagram below and explained in subsequent sections:

    Load all cached data from a static cache key
    Load multiple, targeted items from a dynamic cache key
    Load a single, targeted item from a dynamic cache key

    Loading multiple items from dynamic cache keys

    hashtag
    Introduction

    This approach assumes that the cache to be loaded was added with a payload variable for the cache key, and is comprised of multiple, single-record payloads (having been through a flow control shape).

    Each of these payloads has its own, unique cache key (when data was added to the cache, this key was generated dynamically by resolving a cache key payload variable).

    circle-info

    For more information about this stage, please see .

    When we come to load this data, we must target the required cache keys. In the same way that we use a payload variable to add data to a cache with dynamic cache keys, we can use a payload variable to load data from these keys.

    To do this, you configure a load from cache shape with a 'multi-pick' payload variable in the cache key, and ensure that data passed into this shape contains the values required to resolve this variable.

    hashtag
    How it works

    In summary, you can drop a single shape into a process flow and specify a payload variable as the required cache key. This must be in the form:

    ...where <element> should be replaced with whichever data element you will be passing in to to resolve the cache key. For example:

    circle-info

    The <element> defined here will be the same data element that was specified in the payload variable for the corresponding add to cache shape.

    You then need to pass in any <element> values that should be used to resolve required cache key names. This might be achieved via a (if values are being generated from another system), or perhaps a shape. Whichever shape you use must be placed immediately before the load from cache shape.

    hashtag
    Example

    To help understand how this approach works, we will step through an example.

    Suppose we have the scenario where a process flow has been built to receives incoming orders, and another process flow needs to target specific orders received from this flow.

    To allow the second process flow access to orders processed by the first, we must add all incoming orders to a company type cache in the first process flow (remember that company type caches can be accessed by any other process flow created for your company profile). To ensure that we can go on to target specific orders from this cache later, we will cache every order in its own cache key, using a payload variable.

    To retrieve specific orders from the cache created in the first process flow, we will pass the required order ids into a load from cache shape. These ids will be used to resolve dynamic cache keys, using a payload variable.

    hashtag
    Process flow 1: Add to cache

    Here, we will batch an 'orders' payload into single order payloads - then we'll add each payload to its own cache key, which is created dynamically from a payload variable. Let's break these steps down:

    hashtag
    Process flow 2: Load from cache

    Here, we will pass the required order ids into a load from cache shape. These ids are then used to resolve dynamic cache keys (via a payload variable) to determine which orders should be loaded. Let's break these steps down:

    Step 1: Manual payload

    The contains an 'orders' payload with 17 orders in total.

    Step 2: Filter

    The ensures that orders are only processed if the id field is not empty.

    Step 3: Flow control

    The is set to create batches of 1 from the payload root level - so every order will be added to its own payload.

    Step 4: Add to cache

    The is defined to add to a company type cache, named CPT-722. The cache key is created dynamically, where the first part is always order-followed by the value of the first id element found in the incoming payload. E.g. order-5697116045650. All data from the incoming payload will be added to this cache key. Taking our example using flow control, the incoming payload will only ever be a single order.

    Step 5: Run flow

    When this process flow runs, checking payload information for the shows that 17 payloads have been cached - one payload for each order.

    Step 1: Manual payload

    The contains two order ids that we want to load from our cache.

    Step 2: Load from cache

    The is configured to load data from our CPT-722 cache, targeting dynamic cache keys from order-[[payload.*.id]]. Here, the required cache key(s) will be resolved from all (*) ids found in the incoming payload - in this case order-5693105439058 and order-5697116045650.

    Step 3: Run flow

    When this process flow runs, checking payload information for the shows that two payloads have been loaded - one for each of our given ids.

    Generating dynamic cache keys with payload variables
    load from cache
    connection shape
    manual payload
    Process flow 1: Add to cache
    Process flow 2: Load from cache
    [[payload.*.<element>]]
    [[payload.*.id]]
    manual payload shape
    filter shape
    flow control shape
    add to cache shape
    add to cache shape
    manual payload shape
    load from cache shape
    load from cache shape