The KeyValueMapOperation policy is designed to provide lightweight persistence for data that needs to be accessed by policies or code running on API Platform. KeyValueMapOperations are typically used to persist information that needs to be reused over multiple request/response transactions, such as SessionIds. KeyValueMaps can be used to temporarily write to a cache, or they can be used to persist data in API Platform data store.
KeyValue refers to any arbitrary data in the format key=value, for example SessionID=sfF8d9fe8ci. KeyValue pairs can be stored, retrieved and deleted by defining policies.
The following operations are supported in the KeyValueMapOperations policy.
- PUT: Writes an entry to a KeyValueMap
- GET: Retrieves the value for the key specified
- DELETE: Deletes the key or value specified
Note: KeyValueMaps can also be managed using the API Platform API. Refer to the API Platform API reference for details on the KeyValueMaps API.
Configuring the KeyValueMapOperation policy
Configure the KeyValueMap Operation policy using the following elements.
| Field Name | Description | |||||
|---|---|---|---|---|---|---|
| Scope (Optional) |
Valid values: organization, environment, apiproxy
Default value: environment
Defines the boundary of accessibility for KeyValueMaps. The default scope is environment, meaning that, by default, maps entries are shared by all API proxies running in an environment.
|
|||||
| ExpiryTimeInSecs (Optional) |
Indicates the duration of a specific key entry being retained in the KeyValueMap before it expires. In the example below, the map entry expires after 60 seconds.
The default value is -1, which indicates that the entry never expires.
|
|||||
ExclusiveCache (DEPRECATED: Use Scope instead.) |
Valid values: true/false
Default value: false
If false, the cache provided by the environment is used.
If true, a cache is created exclusively.
|
|||||
| InitialEntries (Optional) | Entry | Key | Parameter (Mandatory) | Seed values for KeyValueMaps, which are populated in the KeyValueMap when it is initialized. A key can be composite, which means that more than one parameter can be appended to make the key. For example, userID and key. |
||
| Value (Mandatory) | Specifies the value for a key. In the example below, the map is initialized by the two key-value entries [k1] -> [v1, v2] and [k2, k3] -> [v3, v4]. | |||||
| Put (Mandatory) | Key | Parameter (Mandatory) | Includes an entry inside a KeyValueMap for the specified key. | |||
| Value (Mandatory) | You can specify multiple values for a key. | |||||
| Override |
Valid values: true/false
Default value: false
If true, it overrides the value for a key.
|
|||||
| Get (Mandatory) | Key | Parameter (Mandatory) | Retrieves a value for the specified key. | |||
| assignTo (Mandatory) | Assigns the retrieved value to a flow variable or simply a variable. | |||||
| index (Optional) | You can specify an index for a multi-valued key. In the example below, index is 1, meaning the value at index 1 is fetched and assigned to the variable myvar. If not specified, all the values of that entry are assigned to the variable as java.util.List. | |||||
| Delete (Mandatory) | Key | Parameter (Mandatory) | Specifies the key to be deleted. | |||
Policy schema
Each policy must conform to a policy schema. All policy constructs such as elements and attributes mentioned above are defined in a schema. To download the schema, click here.