@pothos/core
Version:
Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript
25 lines (24 loc) • 762 B
JavaScript
export const contextCacheSymbol = Symbol.for("Pothos.contextCache");
export function initContextCache() {
return {
[contextCacheSymbol]: {}
};
}
export function createContextCache(create) {
const cache = new WeakMap();
const getOrCreate = (context, ...args) => {
const cacheKey = context[contextCacheSymbol] || context;
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
const entry = create(context, ...args);
cache.set(cacheKey, entry);
return entry;
};
getOrCreate.delete = (context) => {
const cacheKey = context[contextCacheSymbol] || context;
cache.delete(cacheKey);
};
return getOrCreate;
}
//# sourceMappingURL=context-cache.js.map