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

HTTP caching fails after initial Max Age expiry #2435

Closed
chamil321 opened this issue Nov 25, 2021 · 0 comments · Fixed by ballerina-platform/module-ballerina-http#757
Closed
Assignees
Labels
module/http Team/PCM Protocol connector packages related issues Type/Bug

Comments

@chamil321
Copy link
Contributor

chamil321 commented Nov 25, 2021

Description:

$subject and hits the backend rather taking the caches response. The issue lies with the age calculation

Steps to reproduce:

import ballerina/http;
import ballerina/log;

http:Client cachingEP = checkpanic new ("http://localhost:8080",
                             {cache: {enabled: true, isShared: true}});
service /cache on new http:Listener(9090) {

    resource function get .(http:Caller caller, http:Request req) {
        http:Response|error response = cachingEP->forward("/hello", req);

        if (response is http:Response) {
            var result = caller->respond(response);
            if (result is error) {
                log:printError("Failed to respond to the caller", result);
            }
        } else {
            http:Response res = new;
            res.statusCode = 500;
            res.setPayload(response.message());
            var result = caller->respond(res);
            if (result is error) {
                log:printError("Failed to respond to the caller", result);
            }
        }
    }
}



service /hello on new http:Listener(8080) {

    resource function 'default .(http:Caller caller, http:Request req) {
        json payload = {"message": "Hello, World!"};
        http:Response res = new;
        http:ResponseCacheControl resCC = new;
        resCC.maxAge = 15;
        resCC.mustRevalidate = true;
        resCC.isPrivate = false;

        res.cacheControl = resCC;

        res.setETag(payload);
        res.setLastModified();

        res.setPayload(payload);

        var result = caller->respond(res);
        if (result is error) {
            log:printError("Failed to respond to the caller", result);
        }
    }
}
Invocation 1 : Hit backend : 200 OK response
Invocation 2 : Within max age : Take from cache
Invocation 3 : After max age timeout : Hit backend : 304 Not modified response
Invocation 4 : Within 2nd max age : Hit backend : 304 Not modified response // this is problematic

Affected Versions:
SL beta 4

@chamil321 chamil321 added Type/Bug module/http Team/PCM Protocol connector packages related issues labels Nov 25, 2021
@chamil321 chamil321 added this to the Ballerina Swan Lake - Beta5 milestone Nov 25, 2021
@chamil321 chamil321 changed the title HTTP caching fails after initial Max Age expires HTTP caching fails after initial Max Age expiry Nov 25, 2021
@chamil321 chamil321 self-assigned this Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module/http Team/PCM Protocol connector packages related issues Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant