Cache component holds data in an in-memory lookup table as a set of name value pairs, identified by one or more designated key name value pairs. A set of key fields and data fields are defined in the CPS of the component. The component stores values for the defined fields as Name Value pairs, where name is the name of the field and value is the data held in the field. A field can be a key field or a data field.

The component supports the following operations

  • lookup – returns all the data fields that are mapped for a given key field from the in-memory lookup table.
  • add – adds a set of mappings from key field to data fields to the in-memory lookup table.
  • update – updates a set of mappings that are defined for a key field in the in-memory lookup table.
  • delete – deletes a set of mappings that are defined for a key field in the in-memory lookup table.

The component has the following ports:

  • ADD_PORT – Input port ADD_PORT is used to send input request to perform add, update or lookup operations.
  • DEL_PORT – Input port DEL_PORT is used to send input request to perform delete operations.
  • OUT_PORT – Output port OUT_PORT is used to read output request that contains results of add, lookup, update or delete operations.

Configuration and Testing

Component Configuration panel in the CPS (Configuration Property Sheet) allows customization in the component.


Figure 1: CPS of Cache component

Attributes

Error handling configuration

Please refer to the Error Handling section in the Common Configurations section for details.

Field Definition Table

Click the ellipses  button to launch Field Definition Table, the editor to define fields.


Figure 2: Editor to define fields in the lookup table

The Field Definition Table contains Name, Type and Key fields.

  • Name: Name of the field.
  • Type: Data type of the field. Data type field contains the following field values – int, long, short, float, double, boolean, string and date.
  • Key: Specifies whether the current field is a Key or a Data field.
    To define field definitions, perform the following actions:
    1. Click the Add button to add a new field definition.
    2. Edit the value in the Name column of the newly added row and provide the name of the field.
    3. Select the data type of the field value from the drop-down list in the Type column.
    4. Select the checkbox in the Key column if the field is a key field.
    5. Repeat steps 1 to 4 to add all field definitions required.
    6. Click Ok.
  • XSD: XML schema can be specified only if the data type is XML.
Icon
  • To delete any field definitions, select the field definitions and click Remove.
  • There should be at least one key field and one data field defined in the Field Definition Table.

Cache threshold

This property determines the maximum number of entries that are held in the lookup table. If the number of entries in the lookup table exceeds the value defined by this property, oldest entries are discarded based on the Criteria to remove entry property.

Icon
  • The value should be either -1 or greater than 0.
    • -1 implies infinite threshold size.
  • An entry is removed from lookup table only after addition of an entry results in cache size exceeding the value defined by this property. The entry is removed in the same operation which adds the additional entry.
  • The property Criteria to remove entry (explained in the section below) is visible only when this value is greater than 0.
Criteria to remove entry

When a threshold is defined, this property determines which entry should be removed after the threshold is reached. The figure below shows all the available options.

Icon

This property appears only when the property Cache threshold is greater than 0.


Figure 3: Criteria for removing entries after the threshold is reached

  • Least recently added - The oldest entry in the lookup table will be removed first irrespective of the frequency at which an entry is used/updated.
  • Least recently updated - The entry which has been in the lookup table for the longest duration without being updated will be removed.
  • Least recently accessed – The entry has been in the lookup table for the longest time without being looked up or updated for the longest duration will be removed first

Expiry after timeout?

This property is used to determine whether entries should be deleted from the cache after the timeout or not.

On enabling the Expiry After Timeout? property, the Timeout option appears.

Timeout

This contains the timeout value in minutes after which the cache entries will be removed from the cache.

For example, if an entry is made to the cache at 2 pm and Timeout is given as 2 minutes, then the entry gets deleted at 2:02 pm.

Initial cache size

Initial size with which the lookup table has to be initialized. The table will be resized depending on the underlying implementation. Providing an appropriate initial size will reduce the number of resizes.

Validate input

This property determines whether the input message has to be validated against the schema defined on the input ports.

  • If enabled, input messages are validated against the schema defined on the input port on which the message is received.
  • If disabled, input messages are not validated. 
Icon

If the input message is not valid and the input validation is disabled, the behavior of the component is undefined.

Expert Properties

Enable the Expert Properties view to configure these properties.

Icon

Expert properties are meant for advanced users.


Figure 4: CPS of Cache component with Expert Properties enabled and highlighted

Pre Processing XSL Configuration

Pre Processing XSL configuration can be used to transform request message before processing it. Click the ellipses button against the property to configure the properties.

Refer to the Pre/Post Processing XSL Configuration section under the Common Configurations page for details regarding Pre Processing XSL configuration and Post Processing XSL configuration (below).

Post Processing XSL Configuration 

Post Processing XSL configuration can be used to transform response message before sending it to the output port.

Process Message Based on Property

The property helps components to skip certain messages from processing.

Refer to the Process Message Based On a Property section under the Common Configurations page.

Threadpool Configuration

 This property is used when there is a need to process messages in parallel within the component, still maintaining the sequence from the external perspective. 

Refer to the Threadpool Configuration section under the Common Configurations page.

Input and Output

The schema for input and output are auto-generated based on the field definitions provided in the CPS.

Input

The structure of messages on ADD_PORT for the field definitions shown in Figure 2 is shown in the figure below.


Figure 5: Structure of messages on ADD_PORT

Icon

If the value is not defined for any of the keys, the behavior is not defined.

When a message is received on the ADD_PORT an entry is added, updated or looked up from lookup table based on the elements defined in the input message.

  • An add operation is performed if Data element is present under CacheEntry element and at least one of the data fields is present and the value defined for a key field is not already present in the lookup table.
  • An update operation is performed if Data element is present under CacheEntry element and at least one of the data fields is present and the value defined for a key field is already present in the lookup table.
  • A lookup operation is performed if Data element is not present under CacheEntry element or none of the data fields are present.
  • A lookup of all entries is performed if All element is present as defined in the structure.

The structure of messages on DEL_PORT for the field definitions shown in Figure 2 is shown in the figure below.


Figure 6: Structure of messages on DEL_PORT

Icon

If the value is not defined for any of the keys, the behavior is not defined.

Output

The figure below contains the structure of messages on OUT_PORT for the field definitions shown in Figure 2.


Figure 7: Structure of messages on OUT_PORT

Functional Demonstration

Scenario 1

This scenario demonstrates the functioning of the Cache component. Perform the steps shown in this scenario in strict order.
Configure the Cache component as shown in Figure 2 and create a flow as shown in the figure below. Output port of AddUpdateLookupRequest should be connected to ADD_PORT and output port of DeleteRequest should be connected to DEL_PORT.


Figure 8: Sample flow to demonstrate Scenario 1

Add operation

Send the input shown in the figure below from Feeder AddUpdateLookupRequest to add the following entries to lookup table.

  • ssn:ssn1234 → location:New York, EmployeeName:John Williams, ...
  • emp_id:9876 → location:New York, EmployeeName:John Williams, ...

Where an entry is in form <key field name>:<key field value> → <data field name>:<data field value>, <data field name>:<data field value>....


Figure 9: Input for the Add operation

The output message contains all the entries that are added as shown in the figure below.


Figure 10: Result of the Add operation

Update operation

Send the input shown in the figure below from Feeder AddUpdateLookupRequest to update the name field for the entry with key field ssn whose value is ssn1234.


Figure 11: Input for the Update operation

The output message contains the updated entry.


Figure 12: Result of the Update operation

Entries in the database after the update operation are:

  • ssn:ssn1234 → location:London, EmployeeName:John Williams, ...
  • emp_id:9876 → location:London, EmployeeName:John Williams, ...
Icon

Since both key fields ssn and emp_id are defined under single CacheEntry element in the input of add operation shown in Figure 9, updating a data field value for entry corresponding to ssn key field implicitly updates the entry for emp_id key field as well.

In general, all the key fields defined under single CacheEntry maintain same reference to data fields and updating one effects the other. If this is not the desired behavior, modify the input to contain to CacheEntry elements one for each key field. 


Figure 13: Input in Figure 9 modified for not maintaining the same reference for key fields

Lookup operation

Send the input shown in the figure below from Feeder AddUpdateLookupRequest to lookup the name and age fields for the entry with key field ssn whose value is ssn1234.


Figure 14: Input for the Lookup operation

The output message contains the entries looked up from lookup table as shown in the figure below.


Figure 15: Result of the Lookup operation

To lookup all the entries in the lookup send, the input shown in the figure below from AddUpdateLookupRequest.


Figure 16: Input for lookup of all entries

The output containing all the entries in the lookup table is shown in the figure below.


Figure 17: Output of lookup of all entries

Delete operation

Send the input shown in the figure below from Feeder DeleteRequest to delete the entry with key field ssn whose value is ssn1234.


Figure 18: Input for the Delete operation

The output message contains the entries that are deleted from lookup table.


Figure 19: Output for the Delete operation

Send the input shown in the figure below from Feeder DeleteRequest to delete all entries in lookup table.


Figure 20: Input for deleting all entries

The output message contains the entries that are deleted from lookup table. Since there is only undeleted entry in the database, the output message contains only one entry.


Figure 21: Result of delete all entries operation

Useful Tips

  • Size of the lookup table should be within in the memory limit available for the component.
  • The lookup table should always be populated after the component starts as the lookup table is not persisted implicitly.
  • Use this component in conjunction with a DB component to improve the performance of lookups and updates.
  • Lookup can be performed using any of key fields which are part of add request.
  • Update to any key field also affects the lookup data returned by other key fields which are part of add request.
  • Disable input message validation to improve the performance of the component.
  • Send All element in the input request on ADD_PORT to retrieve all the entries from the lookup table
  • Send All element in the input request on DEL_PORT to delete all the entries from the lookup table
  • When performing multiple add, update or lookup operation in a single input request on ADD_PORT the output contains the corresponding result for each of the operation based on the state of lookup table when the operation is performed. If operations are performed in the order - add, lookup, add, lookup – the first lookup will contain only entry but the second lookup contain both the entries.
Adaptavist ThemeBuilder EngineAtlassian Confluence