# Cached

## <mark style="color:purple;">`cached`</mark>(*ttl*: *int*, *respect*: *str* =’*order\_pos*’)(*cached\_value*: *str*)

Function that is typically used for caching equitation results of <mark style="color:red;">`cached_value`</mark> formula.

<mark style="color:red;">`cached_value`</mark> string representation is used as a key for cache

<mark style="color:red;">`ttl`</mark> positive integer which is defines time-to-live for cache

<mark style="color:red;">`respect`</mark> one of (default <mark style="color:red;">`order_pos`</mark>):

* <mark style="color:red;">`order_pos`</mark> - calculate <mark style="color:red;">`cached_value`</mark> for each order in grid
* <mark style="color:red;">`grid`</mark> - calculate <mark style="color:red;">`cached_value`</mark> for the whole grid
* <mark style="color:red;">`bot`</mark> - calculate <mark style="color:red;">`cached_value`</mark> for the whole bot
* <mark style="color:red;">`global`</mark> - calculate <mark style="color:red;">`cached_value`</mark> . Results are used for all bots

{% hint style="warning" %} <mark style="color:red;">`respect=”order_pos”`</mark> must not be used with <mark style="color:red;">`update_balance_formula`</mark> inside group and bot
{% endhint %}

{% hint style="warning" %} <mark style="color:red;">`respect=”grid”`</mark> must not be used with <mark style="color:red;">`update_balance_formula`</mark> inside group and bot
{% endhint %}

{% hint style="warning" %} <mark style="color:red;">`respect=”bot”`</mark> must not be used with <mark style="color:red;">`update_balance_formula`</mark> inside group
{% endhint %}

<mark style="color:red;">`respect='order_pos'`</mark> orders are the same during <mark style="color:red;">`ttl`</mark> seconds

<mark style="color:red;">`respect='grid'`</mark> all orders are placed with the same inside one grid during <mark style="color:red;">`ttl`</mark> seconds

{% hint style="warning" %}
Grids must exist to use this type of cache due to the need to get the <mark style="color:red;">`grid.id`</mark>
{% endhint %}

but the price changes between grids

<mark style="color:red;">`respect='bot'`</mark> all orders are placed with the same over the all grids in one bot during <mark style="color:red;">`ttl`</mark> seconds \*Warning: bot must exist to use this type of cache due to the need to get the <mark style="color:red;">`bot.id`</mark>

<mark style="color:red;">`respect='global'`</mark> all orders are placed with the same over the all bots during `ttl` seconds

Example:
