Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Return the cache value for key value "accountRef".

Code Block
$result = cache("accountRef", _cacheValue + 1)


Example- generating UIDs

This example is for the case where a user wants to generate UIDs in a specific way.

In this example the stream receives updates for records in the system. So it can receive both records that exist in the system already, and those that are new. This stream is used to correctly set/lookup the various ID fields.

Now if 3 records came into this stream that had the same value for a specific attribute (e.g. another ID field such as "BarcodeNumber"), then we do not want to generate a new ID for each record... we want to generate it once and then use that value for the other records.


Code Block
do(
	if($newRecord,
	//then
		do(
            $recordID =
			cache(_out.BarcodeNumber,
				if( _cacheValue == _NULL,
					$recordID = nextValue('RecordID'),
					_cacheValue
                )
            )
                
		),
	//else
		$recordID = in.RecordID
    ),
    $recordID
)


This expression above uses the cache function to hold a newly generated ID (nextValue('RecordID') in memory for each unique _out.BarcodeNumber field. So the 1st record that is processed gets the new ID generated by the sequence, then any subsequent records that are processed will find a match for their BarcodeNumber in the cache, and take that ID that was generated for the 1st BarcodeNumber.


See Also