mastercache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
72 lines (69 loc) • 2.29 kB
JavaScript
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/cache/stack/cache-stack-writer.ts
var cache_stack_writer_exports = {};
__export(cache_stack_writer_exports, {
CacheStackWriter: () => CacheStackWriter
});
module.exports = __toCommonJS(cache_stack_writer_exports);
// src/events/cache/cache-written.ts
var CacheWritten = class {
constructor(key, value, store) {
this.key = key;
this.value = value;
this.store = store;
}
name = "cache:written";
toJSON() {
return {
key: this.key,
store: this.store,
value: this.value
};
}
};
// src/cache/stack/cache-stack-writer.ts
var CacheStackWriter = class {
constructor(cacheStack) {
this.cacheStack = cacheStack;
}
/**
* Write a value in the cache stack
* - Set value in local cache
* - Set value in remote cache
* - Publish a message to the bus
* - Emit a CacheWritten event
*/
async set(key, value, options) {
const item = this.cacheStack.serialize({
value,
logicalExpiration: options.logicalTtlFromNow(),
earlyExpiration: options.earlyExpireTtlFromNow()
});
this.cacheStack.l1?.set(key, item, options);
await this.cacheStack.l2?.set(key, item, options);
await this.cacheStack.publish({ type: "set" /* Set */, keys: [key] });
this.cacheStack.emit(new CacheWritten(key, value, this.cacheStack.name));
return true;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CacheStackWriter
});
//# sourceMappingURL=cache-stack-writer.cjs.map