Cache Fetch Flow BehaviorLast Updated: 08/08/2016 Introduced in Verision: 3.2 |
This tutorial demonstrates how to use Cache Fetch Flow Behavior. This Flow Behavior can be used to fill the cache in with data that we need to keep for a certain time. Additionally, this tutorial demonstrates how to get a collection of data from cache and how to add items to the cache collection.
Note: in Decisions 3.5 this Flow Behavior was changed to System Cache Fetch Flow Behavior.
Example:
In this example we are going to generate a collection of Names and Cache this collection. Next, we are going to use this Flow to fill a custom created Cache Type. Finally, we are going to get all items from the custom Cache Type, add another item to the Cached collection, and check if the Item was added to the Cached collection.
We begin in the Designer Folder with clicking Create Flow on the Folder Actions Panel.
Then, we are going to Name the Flow and define its Behavior as Cache Fetch Flow Behavior. Click Create to proceed to the Flow Designer.
In the Flow Designer we add Create Data step from the Favorite Steps category.
In the resulting window we use Add New link to define a List of Strings variable.
Then, we are going to define another String variable for the Cache Key in Create Data step.
When our variables for Create Data are defined, we can click Add to continue building our Flow.
Then, we add ForLoop Step from the All Steps [Catalog] > Flow Management category.
On the Next outcome from the ForLoop Step we add Generate Random Full Name Step from the All Steps [Catalog] > Data > Text > TestData category.
Next, after Generate Full Name step on the workspace we add Add Item To List Step from the All Steps [Catalog] > Data > List category.
Then, we connect Done outcome from the Add Item To List Step back to the ForLoop step, and Done outcome from the ForLoop step to the Cache Value End Step in our Flow.
Next, we select Create Data step on the workspace, define Constant Value for key Input, and select Show Mapping Editor option.
In the Mapping Editor in the Outputs from > Create Data section we connect Key to the key outcome. In this way we Change Value of the Key Input into the Flow. Save and close Mapping Editor.
Then, we select ForLoop step on the workspace and define Constant No Of Iterations.
Next, we select Add Item To List step and select Show Mapping Editor option.
Data is mapped as following for this step… We add the Generated Name as a New Item to the ListOfNames as Original List. In the Output from Add Item To List we Change Value of the ListOfNames list with the New List. Save and close Mapping Editor when finished.
Finally, we select Cache Value End Step on the workspace and Select Value of ListOfNames variable for the Value Input to the step.
Optionally, we could build some logic in our Flow and decide which Names we would like to cache and which we wouldn’t…
This completes our Flow For Cache. We can save the Flow and close Flow Designer.
Next, we are going to create a custom Cache that will be filled with the Flow that we just created. Navigate to the System > Administration > Cache Folder in the Portal. Then, from the Folder Actions Panel we click Add > TimeCacheDefinition.
In the Add Time Cache Definition window we check Fill Cache Using Flow check-box. Then, we pick Cache Fill Flow that we created previously in this tutorial.
Next, we Name our Cache in the Configuration Name field. From the Target Cache Config Name dropdown list we pick Default.MemoryCache.
Finally, with the Check On Interval Span we define life cycle for our Cache. Click Ok to save Cache definition.
We can confirm that our Cache was successfully saved in the Cache Folder and is ready for use.
Next, we are going to create a simple Flow to test if our Cache is filled in with our Flow For Cache and if we are able to retrieve cached Names or add new Names to this cached collection. Navigate to the Designer Folder and click Create Flow on the Folder Actions Panel.
Next, Name the Flow and click Create to proceed to the Flow Designer.
In the Flow Designer we add [List] Get From Cache step from the All Steps [Catalog] > Data > Cache category.
Next, we add [List] Add Item step from the All Steps [Catalog] > Data > Cache category.
Finally, we add another [List] Get From Cache step from the All Steps [Catalog] > Data > Cache category to check if our new Item was successfully added to the cached collection. Connect the outcome to the End Step in the Flow.
Then, select first [List] Get From Cache step on the workspace and configure data mapping as following. First, provide CacheName and from the CachTypeName dropdown select our custom Cache that we created previously.
Next, we define Constant Value for the Key Input. Note that in this example key value should match the key value that we defined in the Create Data step in the Flow For Cache.
Then, we select [List] Add Item step on the Flow and configure Data Mapping as following… We pick our Custom Cache, define Constant Key Value that matches the key of our cached collection and define Constant Value for the Item to add.
Finally, we select second [List] Get From Cache step in our Flow and configure Data mapping for this step in the exactly same manner as we did for the first [List] Get From Cache step.
This completes our Flow. We can click Debug Flow link on the top panel of the Flow Designer to test our Flow.
Note that in Decisions version 3.5 and above, you’ll need to click on Test Flow rather than Debug Flow.
In the Debugger our Flow executes to the End step with no issues. We can observe Data Flows in the Flow. Select first [List] Get From Cache step and check what Data outcomes from it. This is a list of 20 Random Names generated and cached in the Flow For Cache as we designed.
Then, we select [List] Add Item step and see that we Input new Item to the cached collection.
If we select second [List] Get From Cache step we should see that our New Item is successfully added to the Cached collection.
Note: this collection will only exist in the memory for 3 minutes as we defined when created our custom Cache Definition.