Cleanup Schema cache per request (#6126)
* remove enableSingleSchemaCache from test * clear schema cache per request
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user