serverless-appsync-plugin
serverless-appsync-plugin copied to clipboard
Feature request: Add `enabled` option for caching
I have an AppSync config that I deploy to multiple environments. Only one of those environments should have caching enabled (production). Unfortunately, I can't find a way to enable/disable the caching config during deployment.
What would be ideal for my use case and remain consistent with other settings is to add an enabled option in the caching config.
caching:
enabled: true # globally turns caching on or off [true|false]
behavior: PER_RESOLVER_CACHING
ttl: 60
type: "SMALL"
I could then set this based on the environment I'm in. Is this possible to add, or is there another way to dynamically configure caching?
I have the same use case. I can take a stab at implementation if no work has been done on it yet.
I didn't attempt an implementation but we could definitely use it.
Sorry, I missed this.
A setting would be great, indeed. Thank you for your suggestion.
As a workaround, here is how we've used it in some projects:
caching: ${file(templates/macros.js):getAppSyncCachingConfig}
in templates/macros.js
const getStage = (serverless) => {
const { stage } = serverless.options
? serverless.options
: serverless.service.provider;
return stage;
};
module.exports = {
getAppSyncCachingConfig(serverless) {
return ['staging', 'prod'].some((s) => getStage(serverless).startsWith(s))
? {
behavior: 'PER_RESOLVER_CACHING',
ttl: 60,
type: 'SMALL',
}
: false;
},
};
Sorry, I missed this.
A setting would be great, indeed. Thank you for your suggestion.
As a workaround, here is how we've used it in some projects:
caching: ${file(templates/macros.js):getAppSyncCachingConfig}in
templates/macros.jsconst getStage = (serverless) => { const { stage } = serverless.options ? serverless.options : serverless.service.provider; return stage; }; module.exports = { getAppSyncCachingConfig(serverless) { return ['staging', 'prod'].some((s) => getStage(serverless).startsWith(s)) ? { behavior: 'PER_RESOLVER_CACHING', ttl: 60, type: 'SMALL', } : false; }, };
We also have a use case for this cause if you leave caching on (SMALL) it will cost about 30 euros per month. When you have an environment per developer that goes up quickly.
This is a clean workaround though! Thanks.
hi @bboure checking the v2 branch: looks like the option for conditional enabling it is still missing?
@jmvalino it is I think it's just not documented (yet). Thanks for raising this.