diff --git a/src/utils.js b/src/utils.js index 31e7a1c..1cf2a74 100644 --- a/src/utils.js +++ b/src/utils.js @@ -76,8 +76,14 @@ export function getModelByName(modelName) { return modelList.filter(model => model.modelName == modelName)[0]; } -export function jsonToCacheKey(obj) { - const normalized = canonicalize(obj); - const hash = crypto.createHash('sha256').update(normalized).digest('hex'); - return hash; +export function getQueryToCacheKey({ model, id, populate }) { + const populateKey = []; + for (const pop of populate) { + if (typeof pop === 'string') { + populateKey.push(pop); + } else if (typeof pop === 'object') { + populateKey.push(pop.path); + } + } + return `${model}:${id?.toString()}-${populateKey.join(',')}`; }