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

cache global with ttl = 0 nor working #80

Closed 91-julian-sanchez closed 3 years ago

91-julian-sanchez commented 3 years ago

when setup ttlInSeconds: 0 and deploy code, deployed cache ttl is 3600 , because const DEFAULT_TTL = 3600;

it is not possible to implement ttl = 0 and this can be very useful to enable global cache without storage but if cache on specific endpoints

DianaIonita commented 3 years ago

Hi @91-julian-sanchez,

Thanks for raising this issue. I'm not entirely sure I understand your use-case, would you mind giving me an example of how setting TTL to 0 can help you?

DianaIonita commented 3 years ago

Values of zero for ttlInSeconds should now be supported in v1.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