DianaIonita / serverless-api-gateway-caching

A plugin for the Serverless framework which helps with configuring caching for API Gateway endpoints.
ISC License
136 stars 35 forks source link

allowed for 0 seconds cache time TTL #85

Closed marc-parillo closed 3 years ago

marc-parillo commented 3 years ago

I discovered that we can't set 0 for TTL so I adjusted ApiGatewayCachingSettings.js to allow for this. In some cases, we want to enable caching for only a few endpoints in the Stage. So, the main Stage caching is set to true with TTL 0 and other endpoints you want to cache can be set to a different TTL.

DianaIonita commented 3 years ago

Hi @marc-parillo,

Thanks for your help. I combined this with a related PR and added a few more tests. It should now be solved in the latest version 1.6.1.

Please note that setting ttlInSeconds: 0 on global cache or function cache has the same effect as setting enabled: false. Using a boolean is the recommended way of disabling caching, because it explicitly says that caching is disabled, as opposed to having to figure that out by reading a completely different property like ttlInSeconds.

Also, if you enable apiGatewayCaching globally, you must specify which endpoints to enable caching for, otherwise it's disabled by default.

For example:

plugins:
  - serverless-api-gateway-caching

custom:
  apiGatewayCaching:
    enabled: true

functions:
  list-cats:
    handler: rest_api/cats/get/handler.handle
    events:
      - http:
          path: /cats
          method: get
          # caching is enabled
          caching:
            enabled: true
  update-cat:
    handler: rest_api/cat/post/handler.handle
    events:
      - http:
          path: /cat/{pawId}
          method: post
          # caching is disabled by default