mastercache
Version:
Multi-tier cache module for Node.js. Redis, Upstash, CloudfareKV, File, in-memory and others drivers
63 lines (54 loc) • 1.42 kB
text/typescript
import type {
CreateBusDriverResult,
CreateDriverResult,
L1CacheDriver,
L2CacheDriver,
RawCommonOptions,
} from './types/main';
export class MasterStore {
constructor(baseOptions: RawCommonOptions & { prefix?: string } = {}) {
this.
}
/**
* Add a L1 layer to your store. This is usually a memory driver
* for fast access purposes.
*/
useL1Layer(driver: CreateDriverResult<L1CacheDriver>) {
this.
return this;
}
/**
* Add a L2 layer to your store. This is usually something
* distributed like Redis, DynamoDB, Sql database, etc.
*/
useL2Layer(driver: CreateDriverResult<L2CacheDriver>) {
this.
return this;
}
/**
* Add a bus to your store. It will be used to synchronize L1 layers between
* different instances of your application.
*/
useBus(bus: CreateBusDriverResult) {
this.
return this;
}
get entry() {
return {
options: this.
l1: this.
l2: this.
bus: this.
};
}
}
/**
* Create a new store
*/
export function masterstore(options?: RawCommonOptions & { prefix?: string }) {
return new MasterStore(options);
}