【发布时间】:2019-11-18 11:39:38
【问题描述】:
我有一个循环,在其中我从反应调用后端(django)的请求,当用户单击开始时,前端开始调用请求并且用户正在获取 base 64 格式的图像作为响应,这个请求正在循环运行,并且在每个请求中都获得 1 张图像,现在的问题是,在网络选项卡中,谷歌浏览器的缓存内存已满,因为每个响应都会收到很多图像,如何解决这个问题,我该如何清除网络标签响应。
runInfinite=()=>{
let payload={
iterator:this.state.iterator
};
axios.post('http://127.0.0.1:8000/faceapp/process_image/', payload)
.then(res => {
this.setState({baseimage: res.data}, () => {
console.log(this.state.baseimage.length)
});
this.setState({iterator:this.state.iterator+1})
});
};
stopResults=(e)=>{
e.preventDefault()
axios.get('http://127.0.0.1:8000/faceapp/stop_inference/')
.then(res=>{
console.log(res)
this.setState({flag:false},()=>{
this.setState({baseimage:null})
})
})
}
startResults=(e)=>{
e.preventDefault()
axios.get('http://127.0.0.1:8000/faceapp/start_inference/')
.then(res=>{
this.setState({flag:true})
console.log(res)
})
}
render() {
if (this.state.flag){
this.runInfinite()
}
return (
<Grid fluid>
<Row>
<Col xs={12} md={4} mdOffset={4}>
<h3>Results</h3>
{this.state.baseimage?<img src={"data:image/png;base64," + this.state.baseimage}/>:null}
</Col>
</Row>
<br></br>
<div className="row">
<Col xs={12} md={4} mdOffset={4}>
<button className="hover-button hover-button1" onClick={this.startResults} style={{cursor: "pointer",display: "block",margin: "0 auto",color:"white",width:"50%",height:"36px",border:"none"}}>Start Inference</button>
<br></br>
<button className="hover-button hover-button1" onClick={this.stopResults} style={{cursor: "pointer",display: "block",margin: "0 auto",color:"white",width:"50%",height:"36px",border:"none"}}>Stop Inference</button>
</Col>
{/* <div className="col-sm-12">
<div className="col-sm-6"> </div>
<div className="col-sm-6">
</div>
</div>
</div> */}
</div>
</Grid>
);
}
}
用户将单击开始干扰,runinfinite 将运行,请求将发送并接收将显示在渲染中的图像,当单击停止时,它会停止该功能。但是在运行时 chrome 缓存已满。我已尝试在 index.js 中取消注册服务工作者,但仍然无法正常工作。
【问题讨论】:
-
你应该看看这个问题Link
标签: javascript reactjs google-chrome django-rest-framework browser-cache