Fix cache-key causing problems in memcached (#7021)

* Add memcached to docker-compose

* Use object hash for cache key

Fixes #6823
This commit is contained in:
Rijk van Zanten
2021-07-28 01:18:09 +02:00
committed by GitHub
parent f81dfda20f
commit 206f2380b5
3 changed files with 17 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ const checkCacheMiddleware: RequestHandler = asyncHandler(async (req, res, next)
}
const key = getCacheKey(req);
const cachedData = await cache.get(key);
if (cachedData) {

View File

@@ -1,16 +1,17 @@
import { Request } from 'express';
import url from 'url';
import hash from 'object-hash';
export function getCacheKey(req: Request): string {
const path = url.parse(req.originalUrl).pathname;
let key: string;
const info = {
user: req.accountability?.user || null,
path,
query: path?.includes('/graphql') ? req.sanitizedQuery : req.params.query,
};
if (path?.includes('/graphql')) {
key = `${req.accountability?.user || 'null'}-${path}-${JSON.stringify(req.params.query)}`;
} else {
key = `${req.accountability?.user || 'null'}-${path}-${JSON.stringify(req.sanitizedQuery)}`;
}
const key = hash(info);
return key;
}