About Ajax cache and queue small function, not perfect, please give me more advice

Time:2021-2-22

Post code first:

function ajaxCache(){
    //Request result cache
    var cache = {}
    //Request queue
    var queque = []
    //Request status
    var status = false

    return function (url,data,cb){
        var args = JSON.stringify(data)
        queque.push({
            url:url,
            data:data,
            callback:cb
        })

        var fn = function () {
            if(queque.length){
                var request = queque.shift()
                var params = request.data
                var reqUrl = request.url
                var reqCb = request.callback
                $.ajax({
                    type:"POST",
                    url: baseUrl + reqUrl,
                    data:params,
                    async:false,
                    dataType:'json',
                    success: function(ret){
                        cache[args] = ret
                        reqCb(ret)
                        status = false;
                        fn()
                    }
                });
            }

        }

        //console.log(cache)
        if(cache[args]){
            cb(cache[args])
        }else{
            if(!status){
                fn()
            }
        }
    }
}

Usage:
var getAjaxData = ajaxCache()