简体   繁体   English

如何使用无限请求的 reactjs 清除浏览器的缓存

[英]how to clear cache of browser using reactjs of infinite requests

I have a loop in which I am calling a request to a backend(django) from react, when the user click start, the front end start calling the request and user is getting images in base 64 format in response,this request is running in loop and in every request gets 1 image, now the problem is after sometime the cache memory of google chrome becomes full in network tab as they are lot of images received per response,how to fix this issue, how can I clear the network tab responses.我有一个循环,在其中我从反应调用后端(django)的请求,当用户单击开始时,前端开始调用请求并且用户正在获取 base 64 格式的图像作为响应,此请求正在运行循环并在每个请求中获取 1 张图像,现在问题是在某个时间后,谷歌浏览器的缓存 memory 在网络选项卡中变满,因为每个响应都会收到很多图像,如何解决此问题,如何清除网络选项卡响应.


 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>
        );
    }
}

the user will click on start interference and runinfinite will run and the request will be sending and will receive image which will be display in render and when click on stop it stops the function.But while running the chrome caches become full.I have tried unregister the service worker in index.js but still not working.用户将单击开始干扰,runinfinite 将运行,请求将发送并将接收图像,该图像将显示在渲染中,当单击停止时,它会停止 function。但是在运行时 chrome 缓存已满。我尝试取消注册index.js 中的服务工作者,但仍然无法正常工作。

For clear cache memory in reactjs, there is a package called react-clear-cache using this you can easily clear cache memory. For clear cache memory in reactjs, there is a package called react-clear-cache using this you can easily clear cache memory. link关联

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM