Enable Engine caching

This commit is contained in:
SachaG 2017-12-08 20:54:23 +09:00
parent 68351674da
commit 574f08c449
2 changed files with 23 additions and 16 deletions

View file

@ -24,10 +24,12 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
async resolver(root, {terms = {}}, context, { cacheControl }) {
debug(`//--------------- start ${collectionName} list resolver ---------------//`);
debug(resolverOptions);
debug(terms);
if (cacheControl && resolverOptions.enableCache) {
cacheControl.setCacheHint({ maxAge: resolverOptions.cacheMaxAge });
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
cacheControl.setCacheHint({ maxAge });
}
// get currentUser and Users collection from context
@ -74,7 +76,8 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
debug(documentId);
if (cacheControl && resolverOptions.enableCache) {
cacheControl.setCacheHint({ maxAge: resolverOptions.cacheMaxAge });
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
cacheControl.setCacheHint({ maxAge });
}
const { currentUser, Users } = context;
@ -108,7 +111,8 @@ export const getDefaultResolvers = (collectionName, resolverOptions = defaultOpt
async resolver(root, {terms}, context, { cacheControl }) {
if (cacheControl && resolverOptions.enableCache) {
cacheControl.setCacheHint({ maxAge: resolverOptions.cacheMaxAge });
const maxAge = resolverOptions.cacheMaxAge || defaultOptions.cacheMaxAge;
cacheControl.setCacheHint({ maxAge });
}
const collection = context[collectionName];

View file

@ -34,14 +34,14 @@ const engineConfig = {
// }
// }
// ],
// "stores": [
// {
// "name": "embeddedCache",
// "inMemory": {
// "cacheSize": 10485760
// }
// }
// ],
"stores": [
{
"name": "vulcanCache",
"inMemory": {
"cacheSize": 20000000
}
}
],
// "sessionAuth": {
// "store": "embeddedCache",
// "header": "Authorization"
@ -50,13 +50,16 @@ const engineConfig = {
// {
// "host": "127.0.0.1",
// "port": 3000,
// "endpoint": "/graphql"
// "endpoint": "/graphql",
// "extensions": {
// "strip": []
// }
// }
// ],
// "queryCache": {
// "publicFullQueryStore": "embeddedCache",
// "privateFullQueryStore": "embeddedCache"
// },
"queryCache": {
"publicFullQueryStore": "vulcanCache",
"privateFullQueryStore": "vulcanCache"
},
// "reporting": {
// "endpointUrl": "https://engine-report.apollographql.com",
// "debugReports": true