#####INCLUDE z.upperside.html
Caching lets a reaction learn from its own traffic. Every time the reaction handles a request, MockMotor can save the exchange as a new, temporary cached reaction. The next request that carries the same key values is answered by that cached reaction directly - the original reaction (and, for a forwarding one, the real backend) is not executed again.
Caching is a section of any reaction: static, scripted or forwarding. It is switched on with Cache Transactions: Cache in the reaction's Caching section.
ban=100123.The cached reaction is named after the method, URI and key values (for example POST /accounts ban="100123"), is marked as cached in the reactions list, and is placed so that it takes precedence over the reaction it was recorded from. Changes made to a cached reaction are lost when the cache is cleared. Cached reactions can be deleted in bulk from the service and environment pages.
A cached reaction is never created if the method alone would be its only matching criterion - it would answer every request.
Enter one full expression per line, not just a field name:
| Where the value is | JavaScript / JSONPath | XQuery |
|---|---|---|
| Request body | input.account.id$.account.id | $input//*:ban/text() |
| HTTP (query) parameter | http.parameters.id | $http//*:parameter[@name='id']/text() |
| REST (path) parameter | rest.parameters.userId | $rest//*:parameter[@name='userId']/text() |
| HTTP header | http.headers['X-TxId'] | $http//*:header[@name='X-TxId']/text() |
| Response body (Mock Accounts only) | output.result.id | $output//*:id/text() |
+, &&, ||, ?, ,, =, an opening bracket) continues on the next line, so a multi-line script is still one key.The Save Keys into Accounts setting decides where the key values live.
The key values are hardcoded in each cached reaction's matching script. A request with input.account.id = 18474332674 produces a reaction that matches input.account.id=='18474332674'; another account number produces another reaction. Each cached reaction is self-contained, easy to read and edit, and has nothing to do with accounts.
Use it for recording and replaying a modest number of distinct requests, and whenever you want to see and tweak each case.
The key values (from both the request and the response) are saved as a mock account, and the cached reaction selects that account instead of containing the values. Properties of the payload whose names match the keys are replaced with account variables. This keeps the data in the account store - where it can be browsed, searched, edited and used by other reactions - rather than scattered through many reactions. It also lets keys that come from the response (for example an id the backend generated) be part of the account. See Mock Accounts.
Use it when the recorded data should be shared or manipulated as accounts, or when response values need to travel with the request values.
When the reaction has its own payload (a script or a template), the cached reaction can take it in two ways. This is the Cached Payload setting:
| Cache Result | Cache Script | |
|---|---|---|
| Cached reaction payload | The static text the reaction generated for this request | A copy of the payload script, run again for each request |
| Account selection | None, unless the original reaction also updates or deletes accounts | Copied from the original reaction, with the same "if account not found" behaviour |
| Follows later changes of account data | No - frozen | Yes - reflects the current account values |
| Speed and simplicity | Best - nothing to evaluate | The script runs on every request |
Cache Result is right when the answer depends only on the request: a forwarded response, or a script that merely transforms the input. The cached reaction is a faithful snapshot, independent of accounts and of the script library.
Cache Script is right when the payload reads account values that can change between calls - a balance, a status, a counter updated by other reactions. A frozen result would go stale; the copied script, together with the copied account selection, keeps producing current data.
The default is chosen for you from the payload, and is recalculated every time you switch the toggle to Cache:
$account or $accounts - Cache Script.account or accounts - Cache Script.You can override it either way. A reaction with an empty payload (a plain forward) always caches the response it received.
If the original reaction updates account properties or deletes accounts, the cached reaction does so too, in both modes - the side effects of the transaction are part of what is replayed. For that reason the account selection is copied along with them.
| Setting | Meaning | API / MCP field |
|---|---|---|
| Cache Transactions | Record cached reactions or not | cache |
| Cached Payload | Cache Result (true) or Cache Script (false) | cacheResultPayload |
| Cache Keys | One full expression per line | cacheKeys |
| Save Keys into Accounts | Mock accounts instead of raw reactions | cacheSaveToAccount |
| Max Delay, ms | Cap on the cached reaction's delay | cacheMaxDelay |