Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache fails first time while storing #178

Open
diptiranjan-das opened this issue Jun 7, 2019 · 0 comments
Open

cache fails first time while storing #178

diptiranjan-das opened this issue Jun 7, 2019 · 0 comments

Comments

@diptiranjan-das
Copy link

While calling for the first time to an api, it showing network error but still it saving in cache. For next time it fetching from cache and working. Dynamic injected code in file
-> node_modules\tree-gateway\dist\pipeline\cache\server-cache.js

ServerCache.cacheStore.get(req.originalUrl, function(err, entry){
if (err) {
return next();

}
if (entry) {
    res.contentType(entry.mimeType || "text/html");
    res.send(new Buffer(entry.content, "base64"));
}
else {
    req.parseRespBody = true;
    var send = res.send.bind(res);
    res.send = function (body) {
        var ret = send(body);
        if ( !body ) {
            body = '';
        }
        body = new Buffer(body).toString("base64");
        if ( typeof body !== "string" ) {
            return ret;
        }
        if ((res.statusCode >= 200 && res.statusCode < 300) || (res.statusCode === 304)){
            ServerCache.cacheStore.set(req.originalUrl, {content: body,mimeType: this._headers["content-type"]}, 10000);
        }
        return ret;
    };
    return next();
}

});
return;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant