RTK查询 - 如何在不调用UpdateCacheddata的情况下更新chached数据

发布于 2025-01-19 19:39:17 字数 374 浏览 1 评论 0原文

我正在使用RTK查询,并且有2个不同的数据源:

  1. 正在进行的WebSocket连接,每当收到相关通知时,将使用UpdateCacheddata更新缓存,
  2. HTTP请求向API http请求从DB中获取现有数据,以从DB

中获取CACHED数据,缓存的数据是API的存储。 >查询>端点名称>数据。

当我进行特定的API调用时,我想通过该结果更新缓存的数据。 updatecacheddata不可用于查询。

另外,我应该将缓存数据的副本保留在普通切片的内吗?

谢谢,

我尝试研究该主题,但尚不清楚。有人说,最好将这些数据的副本保留在普通切片的内部并在此处进行更新,但是此数据将无限期地存在。

I am working with rtk query and I have 2 different sources of data:

  1. ongoing websocket connection that updates cache with updateCachedData whenever relevant notification is received,
  2. http requests to the api to get an existing data from db

The cached data is store inside of the api > queries > endpointname > data.

When I made a particular api call I want to update the cached data with that result. updateCachedData is not available for the query.mutation so I am not sure how this can be achieved.

Also, should I keep the copy of that cached data inside of the normal slice?

Thanks

I've tried researching the subject but its unclear. Some people state it's a good idea to keep the copy of that data inside of the normal slice and update it there but then this data will be there indefinitely.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2025-01-26 19:39:17

嗯,听起来你正在尝试使用突变来将数据保存更长时间 - 而突变并不是为此目的。突变意味着对服务器进行更改,而不是更多。

因此,我假设您只是对此处应该是查询的内容使用突变 - 如果您想稍后触发它,也许也是一个惰性查询或带有 skip 的查询选项。

Hmm, that sounds like here you are trying to use a mutation to keep data around for longer - and mutations are just not meant for that. A mutation is meant to make a change on the server, not more.

So I would assume that you are just using a mutation for something that should rather be a query here - if you want to trigger it a little bit later, maybe also a lazy query or a query with a skip option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文