UNPKG

@nerjs/batchloader

Version:

`BatchLoader` is a tool for batching data requests with support for deduplication, caching, and parallel task management. It is designed to enhance flexibility and performance in scenarios requiring asynchronous data processing. This module was inspired b

57 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheAdapter = exports.MapCache = exports.StubCache = void 0; class StubCache { async get(_key) { return Promise.resolve(undefined); } async set(_key, _data) { } async delete(_key) { } async clear() { } } exports.StubCache = StubCache; /** * Simple cache implementation based on Map. * Designed for local in-memory usage. * Methods are implemented with an asynchronous interface for compatibility * with other cache types, such as external databases or distributed systems. * Note that this implementation does not support TTL and relies on external * mechanisms for managing data expiration. */ class MapCache { constructor() { this.map = new Map(); } async get(key) { return this.map.get(key); } async set(key, data) { this.map.set(key, data); } async delete(key) { this.map.delete(key); } async clear() { this.map.clear(); } } exports.MapCache = MapCache; class CacheAdapter { constructor(cache) { this.cache = cache || new StubCache(); } get(key) { return this.cache.get(key); } set(key, data) { return this.cache.set(key, data); } delete(key) { return this.cache.delete(key); } clear() { return this.cache.clear(); } } exports.CacheAdapter = CacheAdapter; //# sourceMappingURL=cache-adapter.js.map