mastercache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
1 lines • 1.69 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/drivers/base-driver.ts"],"sourcesContent":["import type { DriverCommonOptions } from '../types/main';\n\nexport abstract class BaseDriver {\n /**\n * Current cache prefix\n */\n protected prefix: string;\n\n constructor(protected config: DriverCommonOptions) {\n this.prefix = this.#sanitizePrefix(config.prefix);\n }\n\n /**\n * Sanitizes the cache prefix by removing any trailing colons\n */\n #sanitizePrefix(prefix?: string) {\n if (!prefix) return '';\n return prefix.replace(/:+$/, '');\n }\n\n /**\n * Creates a namespace prefix by concatenating the cache prefix with the given namespace\n * If the cache prefix is not defined, the namespace is returned as is\n */\n protected createNamespacePrefix(namespace: string) {\n const sanitizedPrefix = this.#sanitizePrefix(this.prefix);\n return sanitizedPrefix ? `${sanitizedPrefix}:${namespace}` : namespace;\n }\n\n /**\n * Returns the cache key with the prefix added to it, if a prefix is defined\n */\n protected getItemKey(key: string) {\n return this.prefix ? `${this.prefix}:${key}` : key;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAe,aAAf,MAA0B;AAAA,EAM/B,YAAsB,QAA6B;AAA7B;AACpB,SAAK,SAAS,KAAK,gBAAgB,OAAO,MAAM;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAJU;AAAA;AAAA;AAAA;AAAA,EASV,gBAAgB,QAAiB;AAC/B,QAAI,CAAC,OAAQ,QAAO;AACpB,WAAO,OAAO,QAAQ,OAAO,EAAE;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,sBAAsB,WAAmB;AACjD,UAAM,kBAAkB,KAAK,gBAAgB,KAAK,MAAM;AACxD,WAAO,kBAAkB,GAAG,eAAe,IAAI,SAAS,KAAK;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKU,WAAW,KAAa;AAChC,WAAO,KAAK,SAAS,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK;AAAA,EACjD;AACF;","names":[]}