UNPKG

@nasriya/cachify

Version:

A lightweight, extensible in-memory caching library for storing anything, with built-in TTL and customizable cache types.

90 lines (89 loc) 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CachifyClient = void 0; const ext_engines_1 = __importDefault(require("./api/engines/ext.engines")); const ext_persistence_manager_1 = __importDefault(require("./api/persistence/ext.persistence.manager")); const Engines_1 = __importDefault(require("./core/engines/Engines")); const EnginesProxy_1 = __importDefault(require("./core/engines/EnginesProxy")); const events_1 = __importDefault(require("./core/events/events")); const files_manager_1 = __importDefault(require("./core/flavors/files/files.manager")); const kvs_manager_1 = __importDefault(require("./core/flavors/kvs/kvs.manager")); const persistence_manager_1 = __importDefault(require("./core/persistence/persistence.manager")); const proxy_1 = __importDefault(require("./core/persistence/proxy")); class CachifyClient { #_engines = new Engines_1.default(); #_enginesProxy = new EnginesProxy_1.default(this.#_engines); #_persistence = new persistence_manager_1.default(this); #_persistenceProxy = new proxy_1.default(this.#_persistence); #_events = new events_1.default(); #_flavors = { kvs: new kvs_manager_1.default({ enginesProxy: this.#_enginesProxy, persistenceProxy: this.#_persistenceProxy, eventsManager: this.#_events.for.kvs }), files: new files_manager_1.default({ enginesProxy: this.#_enginesProxy, persistenceProxy: this.#_persistenceProxy, eventsManager: this.#_events.for.files }) }; /** * Access the engines manager. * * The engines manager is used to configure and access the engines * used by the cache system to store records. * * @since v1.0.0 */ engines = new ext_engines_1.default(this.#_engines); /** * Retrieves the events broker for the cache system. * * The events broker is used to emit and listen to cache-related events. * * @since v1.0.0 */ get events() { return this.#_events.broker; } /** * Access the key-value cache manager. * @returns {KVCacheManager} * @since v1.0.0 */ get kvs() { return this.#_flavors.kvs; } /** * Access the file cache manager. * @returns {FileCacheManager} * @since v1.0.0 */ get files() { return this.#_flavors.files; } /** * * @since v1.0.0 */ persistence = new ext_persistence_manager_1.default(this.#_persistence, this); /** * Clears the cache for the specified scope or for all scopes if no scope is provided. * * This method delegates the clearing operation to the `clear` method of all cache managers. * * @param {string} [scope] - The scope for which to clear the cache. If not provided, clears all scopes. * @since v1.0.0 */ async clear(scope) { // Call the `clear` method of all cache managers await Promise.all([ this.#_flavors.kvs.clear(scope), this.#_flavors.files.clear(scope), /** * TODO: Once other cache managers are implemented, * call the `clear` method of each cache manager */ ]); } } exports.CachifyClient = CachifyClient; exports.default = CachifyClient;