UNPKG

dino-core

Version:

A dependency injection framework for NodeJS applications

71 lines 2.47 kB
"use strict"; // Copyright 2021 Quirino Brizi [quirino.brizi@gmail.com] // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.CacheContext = void 0; const invalid_value_exception_1 = require("../../exceptions/invalid.value.exception"); class CacheContext { /** * Create a new cache context * * @param {String} cacheName the cache name * @param {Array} excludedMethods the methods to exclude from caching */ constructor(cacheName, excludedMethods, cacheOptions) { this.excludedMethods = [ 'cacheable', 'profile', 'scope', 'lazy', 'dependsOn', 'autoLoad', '__call', 'getTypeName', 'getStereotypeProxyHandler', 'postConstruct', 'preDestroy', 'isPrototypeOf', 'isInstanceOf', 'instanceof', 'hasOwnProperty', 'toString' ]; this.cacheName = cacheName; this.excludedMethods.push(...excludedMethods); this.cacheOptions = cacheOptions; } getCacheName() { return this.cacheName; } getCacheOptions() { return this.cacheOptions; } /** * Determine if the cache is activated for the current method. * * @param {String} method the method name * @returns {Boolean} */ isCacheActivatedFor(method) { return !this.excludedMethods.includes(method); } static create(cacheName, excludedMethods = [], opts = { max: 100, maxAge: 300000, updateAgeOnGet: true }) { if (cacheName === undefined) { throw invalid_value_exception_1.InvalidValueException.create('cache name must be provided'); } return new CacheContext(cacheName, excludedMethods, opts); } } exports.CacheContext = CacheContext; //# sourceMappingURL=cache.context.js.map