Contents

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 support 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


Figure 1: CPS of Cache component

Attributes

Field Definition Table

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


Figure 2: Editor to define fields in 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 Add button to add a new field definition.
    2. Edit the value in Name column of the newly added row and provide the name of the field.
    3. Select the data type of field value from the drop-down list in Type column.
    4. Select the check box in Key column, if the field is a key field.
    5. Repeat steps 1 to 4 to add all field definitions.
    6. Click Ok.
  • XSD: Xml schema can be specified only if 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 property Criteria to remove entry.

Icon
  • Value should be either -1 or greater than 0.
  • -1 implies infinite threshold size.
  • The property Criteria to remove entry is visible only when this value is greater than 0.
  • 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.
Criteria to remove entry

When a threshold is defined, this property determines which entry should be removed after the threshold is reached. Figure 3 shows all the available criteria.

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.
Initial cache size

Initial size with which 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.

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 Figure 4.


Figure 4: 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 Figure 5.


Figure 5: Structure of messages on DEL_PORT

Icon

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

Output

Figure 6 contains the structure of messages on OUT_PORT for the field definitions shown in Figure 2.


Figure 6: 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 Figure 7. Output port of AddUpdateLookupRequest should be connected to ADD_PORT and output port of DeleteRequest should be connected to DEL_PORT.


Figure 7: Sample flow to demonstrate scenario 1

Add operation

Send the input shown in Figure 8 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 8: Input for add operation

The output message contains all the entries that are added as shown in Figure 9.


Figure 9: Result of add operation

Update operation

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


Figure 10: Input for update operation

The output message contains the updated entry as shown in Figure 11.


Figure 11: Result of 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 8, 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 as shown in Figure 12 


Figure 12: Input in Figure 8 modified to not maintain same reference for key fields

Lookup operation

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


Figure 13: Input for lookup operation

The output message contains the entries looked up from lookup table as shown in Figure 14.


Figure 14: Result of lookup operation

To lookup all the entries in the lookup send, the input shown in Figure 15 from AddUpdateLookupRequest.


Figure 15: Input for lookup of all entries

The output containing all the entries in the lookup table is shown in Figure 16.


Figure 16: Output of lookup of all entries

Delete operation

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


Figure 17: Input for delete operation

The output message contains the entries that are deleted from lookup table as shown in Figure 18.


Figure 18: Output for delete operation

Send the input shown in Figure 18 from Feeder DeleteRequest to delete all entries in lookup table.


Figure 19: Input for deleting all entries

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


Figure 20: 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 effects 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 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