bentocache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
37 lines (36 loc) • 984 B
JavaScript
// src/drivers/base_driver.ts
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;
}
};
export {
BaseDriver
};
//# sourceMappingURL=chunk-BO75WXSS.js.map