有没有办法在OPA中存储值
我有一个用例,如果已经定义了变量,则返回该值,否则调用休息端点来获取该变量。
get_value = value {
data.value
value
}else = value {
value := <> #invoke rest
}
我将运行 OPA 作为服务器,我的期望是,在第一次调用中它将转到 else 块,然后转到第一个块以进行其余的调用。请你帮助我好吗
I have a usecase to do like, if a variable is already defined then return that value else invoke a rest endpoint to get the variable.
get_value = value {
data.value
value
}else = value {
value := <> #invoke rest
}
I will be running OPA as a server and my expectation is like, in the first invokation it will go to the else block then to the first block for rest of the calls. Could you please help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法从策略写入内存存储,不。除此之外,您的代码看起来不错,而且我想说,在通过
http.senddata
中是否存在值是一种非常常见的模式代码>.但需要注意的一件事是,您可以在http.send
调用上使用缓存,这将有效地执行与您相同的操作:如果服务器使用缓存标头进行响应,您甚至不会需要使用
force_cache
但可以简单地说cache: true
并且http.send
客户端将根据服务器的建议进行缓存。You cannot write to the in-memory store from a policy, no. Except for that though, your code looks fine, and I'd say it's a pretty common pattern to first check for the existence of a value in
data
before fetching it viahttp.send
. One thing to note though is that you may use caching on thehttp.send
call, which would effectively do the same thing you're after:If the server responds with caching headers, you won't even need to use
force_cache
but can simply saycache: true
and thehttp.send
client will cache according to what the server suggests.