UNPKG

@kotori-bot/core

Version:
87 lines (86 loc) 2.51 kB
/** * @Package @kotori-bot/core * @Version 1.7.0 * @Author Arimura Sena <me@hotaru.icu> * @Copyright 2024-2025 Hotaru. All rights reserved. * @License BAN-ZHINESE-USING * @Link https://github.com/kotorijs/kotori * @Date 17:26:09 */ "use strict"; 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); var cache_exports = {}; __export(cache_exports, { Cache: () => Cache, default: () => cache_default }); module.exports = __toCommonJS(cache_exports); var import_error = require("../utils/error"); var import_app = require("../app"); class Cache extends import_app.Service { cache = /* @__PURE__ */ new Map(); constructor(ctx) { super(ctx, {}, "cache"); } start() { if (this.cache) return; this.cache = /* @__PURE__ */ new Map(); } stop() { if (this.cache) { for (const el of this.cache.values()) el.clear(); this.cache.clear(); } delete this.cache; } /** * Get the container of current content instance. * * @returns THe container */ getContainer() { if (!this.cache) throw new import_error.KotoriError("Cache service is not started.", "cache"); const key = this.ctx.identity ?? "root"; if (!this.cache.has(key)) this.cache.set(key, /* @__PURE__ */ new Map()); return this.cache.get(key); } /** * Get the value from current the container. * * @param prop The property name * @returns The value */ get(prop) { return this.getContainer().get(prop); } /** * Set the value to current the container. * * @param prop The property name * @param value The value */ set(prop, value) { this.getContainer().set(prop, value); } } var cache_default = Cache; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Cache });