UNPKG

prisma-cache-nosql

Version:

<div> <a href="https://www.npmjs.com/package/prisma-cache-nosql"> <img alt="npm" src="https://img.shields.io/npm/v/prisma-cache-nosql?logo=npm&logoColor=white"> </a> <a href="https://github.com/BearToCode/prisma-cache-nosql/blob/master/LICENSE"> <i

38 lines (35 loc) 1.21 kB
import hash from 'object-hash'; function adapterMemory() { const storage = new Map(); return ({ logger }) => ({ async get({ model, operation, args }) { const queryHash = hash({ operation, args }); const key = `${model}:${queryHash}`; logger.module('memory').debug(`Get key ${key}`); const value = storage.get(key); if (value) { logger.module('memory').debug(`Found value:`, value); return JSON.parse(value); } return null; }, async set({ model, operation, args }, value) { const queryHash = hash({ operation, args }); const key = `${model}:${queryHash}`; logger.module('memory').debug(`Set key ${key}`); storage.set(key, JSON.stringify(value)); }, async clear(model) { for (const [key] of storage.entries()) { if (key.startsWith(`${model}:`)) { storage.delete(key); } } }, async clearAll() { storage.clear(); } }); } export { adapterMemory }; //# sourceMappingURL=memory.js.map