Skip to main content

Selection functions

cache

Commentary

added in 1.1.11

Caches the value of on to the values in to. This is a useful function for creating an immutable relationship when using forks doesn't make sense.

Beware that cache is accrete-only, so be careful not to overload memory by caching many values!


Examples

Caching a map

Set on to whatever value dictates the identity of your cache. Set to to any value that will be evaluted.

The effect is that the same on value will always produce the same to value.

{
"topic": "sandbox",
"vars": {
"i": {
"_gen": "oneOf",
"choices": [
1,
2
]
},
"cached": {
"_gen": "cache",
"on": {
"_gen": "var",
"var": "i"
},
"to": {
"x": {
"_gen": "normalDistribution",
"mean": 50,
"sd": 5
}
}
}
},
"value": {
"from": {
"_gen": "var",
"var": "i"
},
"to": {
"_gen": "var",
"var": "cached",
"path": [
"x"
]
}
}
}
[
{
"from": 2,
"to": 45.92117476009821
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 2,
"to": 45.92117476009821
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 1,
"to": 48.47137376354857
},
{
"from": 2,
"to": 45.92117476009821
}
]

Specification

JSON schema

{
"type": "object",
"properties": {
"on": {},
"to": {}
},
"required": [
"on",
"to"
]
}