UNPKG

mastercache

Version:

Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers

60 lines (59 loc) 2 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/drivers/base-driver.ts var base_driver_exports = {}; __export(base_driver_exports, { BaseDriver: () => BaseDriver }); module.exports = __toCommonJS(base_driver_exports); var BaseDriver = class { constructor(config) { this.config = config; this.prefix = this.#sanitizePrefix(config.prefix); } /** * Current cache prefix */ prefix; /** * Sanitizes the cache prefix by removing any trailing colons */ #sanitizePrefix(prefix) { if (!prefix) return ""; return prefix.replace(/:+$/, ""); } /** * Creates a namespace prefix by concatenating the cache prefix with the given namespace * If the cache prefix is not defined, the namespace is returned as is */ createNamespacePrefix(namespace) { const sanitizedPrefix = this.#sanitizePrefix(this.prefix); return sanitizedPrefix ? `${sanitizedPrefix}:${namespace}` : namespace; } /** * Returns the cache key with the prefix added to it, if a prefix is defined */ getItemKey(key) { return this.prefix ? `${this.prefix}:${key}` : key; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { BaseDriver }); //# sourceMappingURL=base-driver.cjs.map