mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
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:
@@ -17,6 +17,7 @@ const checkCacheMiddleware: RequestHandler = asyncHandler(async (req, res, next)
|
||||
}
|
||||
|
||||
const key = getCacheKey(req);
|
||||
|
||||
const cachedData = await cache.get(key);
|
||||
|
||||
if (cachedData) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user