mastercache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
46 lines (45 loc) • 1.2 kB
JavaScript
// 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;
}
};
export {
CacheStackWriter
};
//# sourceMappingURL=cache-stack-writer.js.map