Cleanup Schema cache per request (#6126)

* remove enableSingleSchemaCache from test

* clear schema cache per request
This commit is contained in:
Diamond Lewis
2019-10-11 15:27:15 -05:00
committed by GitHub
parent f26008f031
commit edfa1df454
4 changed files with 112 additions and 21 deletions

View File

@@ -96,6 +96,19 @@ export class RedisCacheAdapter {
})
);
}
// Used for testing
async getAllKeys() {
return new Promise((resolve, reject) => {
this.client.keys('*', (err, keys) => {
if (err) {
reject(err);
} else {
resolve(keys);
}
});
});
}
}
export default RedisCacheAdapter;

View File

@@ -153,6 +153,7 @@ function makeExpressHandler(appId, promiseHandler) {
promiseHandler(req)
.then(
result => {
clearSchemaCache(req);
if (!result.response && !result.location && !result.text) {
log.error(
'the handler did not include a "response" or a "location" field'
@@ -186,13 +187,18 @@ function makeExpressHandler(appId, promiseHandler) {
}
res.json(result.response);
},
error => next(error)
error => {
clearSchemaCache(req);
next(error);
}
)
.catch(e => {
clearSchemaCache(req);
log.error(`Error generating response. ${inspect(e)}`, { error: e });
next(e);
});
} catch (e) {
clearSchemaCache(req);
log.error(`Error handling request: ${inspect(e)}`, { error: e });
next(e);
}
@@ -210,3 +216,9 @@ function maskSensitiveUrl(req) {
}
return maskUrl;
}
function clearSchemaCache(req) {
if (req.config && !req.config.enableSingleSchemaCache) {
req.config.database.schemaCache.clear();
}
}