DianaIonita/serverless-api-gateway-caching

/proxy - cache miss on every request - NestJs

Opened this issue · 1 comments

Followed the examples that the package provides essentially to the letter and yet I'm unable to get the cache to actually return a hit.

APIG says the cache is active, and everything that is configured by the package seems to appear correctly but on this very simple example repo I am unable to get a cache hit.

I would have expected the apigateway header to tell me I have hit the cache, cloudwatch metrics confirms I'm getting cache misses.

Specifically building using typescript/nestjs which requires use of the:
path: /{proxy+}
and I assume also the base path setting
basePath: /dev

I have tried with and without basepath.

Here's my minimalistic repro repo
https://github.com/claridgicus/apigateway-cache-example-repro

Hi @claridgicus,

Thanks for raising the issue and apologies for the delay.

The basePath variable is specifically used when the API Gateway is shared.
According to this plugin's docs:

If the shared gateway has a default base path that is not part of your endpoint configuration, you can specify it using the optional basePath setting.

I'm looking at your example repo and I don't see anything about a shared API Gateway.
If that's correct, then to keep /dev in your path, you can include it as part of your endpoint config:

functions:
  main:
    handler: src/main.handler
    events:
      - http:
          method: any
          path: /dev/{proxy+}
          caching:
            enabled: true
            ttlInSeconds: 5
            cacheKeyParameters:
              - name: request.path.proxy

Please let me know if you're still having problems.