UNPKG

@leyyo/cache

Version:
97 lines (96 loc) 3.43 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheClientAbstract = void 0; // noinspection JSUnusedGlobalSymbols class CacheClientAbstract { constructor(native, provider, description) { CacheClientAbstract._count++; this.num = CacheClientAbstract._count; this.native = native; this.provider = provider; this.description = description ? description : `${provider.name}#${this.num}`; this.notSupportCommands = []; this._clearInfo(); this['$$leyyoType'] = Symbol("leyyo.cache,CacheClient"); } _get(fn) { return __awaiter(this, void 0, void 0, function* () { try { return fn(); } catch (e) { return undefined; } }); } _clearInfo() { if (!this._lastInfo) { setTimeout(() => this._clearInfo(), 30 * 60 * 60000); } else { setTimeout(() => this._clearInfo(), 3 * 60 * 60000); } this._lastInfo = undefined; } _getName() { return __awaiter(this, void 0, void 0, function* () { if (this._lastName) { return this._lastName; } return this.getName(); }); } _getId() { return __awaiter(this, void 0, void 0, function* () { if (this._lastId) { return this._lastId; } return this.getId(); }); } _getInfo() { return __awaiter(this, void 0, void 0, function* () { if (this._lastInfo) { return this._lastInfo; } return this.getInfo(); }); } info(check) { return __awaiter(this, void 0, void 0, function* () { if (!check.clients) { check.clients = []; } if (check.clients.includes(this.num)) { return { num: this.num }; } check.clients.push(this.num); // noinspection ES6MissingAwait const promises = [ this._get(() => this._getId()), this._get(() => this._getName()), this._get(() => this._getInfo()), ]; const [id, name, bulk] = yield Promise.all(promises); return { num: this.num, id, name: name !== null && name !== void 0 ? name : this._lastName, provider: yield this.provider.info(check), description: this.description, bulk }; }); } } exports.CacheClientAbstract = CacheClientAbstract; CacheClientAbstract._count = 0;