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

zero in Cache time-to-live (TTL) #81

Closed 91-julian-sanchez closed 3 years ago

91-julian-sanchez commented 3 years ago

This line this.cacheTtlInSeconds = cachingSettings.ttlInSeconds || DEFAULT_TTL; in ApiGatewayCachingSettings.js , Don't allows setup ttlInSeconds in zero seconds and bug detected it allows setup cacheTtlInSeconds less than zero seconds.

The fix is change OR operator validation by ternary operator, like this: this.cacheTtlInSeconds = cachingSettings.ttlInSeconds >= 0 ? cachingSettings.ttlInSeconds: DEFAULT_TTL;

DianaIonita commented 3 years ago

Hi @91-julian-sanchez,

Thanks for your help. I combined this with a related PR and added a few more things around 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.