RTK查询 - 如何在不调用UpdateCacheddata的情况下更新chached数据
我正在使用RTK查询,并且有2个不同的数据源:
- 正在进行的WebSocket连接,每当收到相关通知时,将使用UpdateCacheddata更新缓存,
- HTTP请求向API http请求从DB中获取现有数据,以从DB
中获取CACHED数据,缓存的数据是API的存储。 >查询>端点名称>数据。
当我进行特定的API调用时,我想通过该结果更新缓存的数据。 updatecacheddata不可用于查询。
另外,我应该将缓存数据的副本保留在普通切片的内吗?
谢谢,
我尝试研究该主题,但尚不清楚。有人说,最好将这些数据的副本保留在普通切片的内部并在此处进行更新,但是此数据将无限期地存在。
I am working with rtk query and I have 2 different sources of data:
- ongoing websocket connection that updates cache with updateCachedData whenever relevant notification is received,
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,听起来你正在尝试使用突变来将数据保存更长时间 - 而突变并不是为此目的。突变意味着对服务器进行更改,而不是更多。
因此,我假设您只是对此处应该是查询的内容使用突变 - 如果您想稍后触发它,也许也是一个惰性查询或带有
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.