UNPKG

@leyyo/cache

Version:
81 lines (80 loc) 2.81 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.CacheRemoteImpl = void 0; const util_1 = require("../util"); // noinspection JSUnusedGlobalSymbols class CacheRemoteImpl { constructor(id) { this.id = id; this._enabled = true; } // noinspection JSUnusedLocalSymbols info(check) { return __awaiter(this, void 0, void 0, function* () { return { id: this.id }; }); } $invalidatorForNotify(data) { if (!this._enabled) { return; } if (this._notifyLambda) { this._notifyLambda(data) .then() .catch(e => console.log(`Error for 'invalidate' in remote: ${this.id}! => ${e.message}`)); } } $invalidatorForInvalidate(data) { if (!this._enabled) { return; } if (this._invalidateLambda) { this._invalidateLambda(data) .then() .catch(e => console.log(`Error for 'invalidate' in remote: ${this.id}! => ${e.message}`)); } } $invalidatorForDelete(data) { if (!this._enabled) { return; } if (this._deleteLambda) { this._deleteLambda(data) .then() .catch(e => console.log(`Error for 'delete' in remote: ${this.id}! => ${e.message}`)); } } setNotifyLambda(lambda) { util_1.cacheUtil.checkLambda('remote.setNotifyLambda', 'lambda', lambda, 1); this._notifyLambda = lambda; } setInvalidateLambda(lambda) { util_1.cacheUtil.checkLambda('remote.setInvalidateLambda', 'lambda', lambda, 1); this._invalidateLambda = lambda; } setDeleteLambda(lambda) { util_1.cacheUtil.checkLambda('remote.setDeleteLambda', 'lambda', lambda, 1); this._deleteLambda = lambda; } disable() { this._enabled = false; } enable() { this._enabled = true; } get enabled() { return this._enabled; } } exports.CacheRemoteImpl = CacheRemoteImpl;