Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/local/lib/node_modules/homebridge-config-ui-x/node_modules/@nestjs/common/cache/interceptors/ drwxr-xr-x | |
| Viewing file: Select action/file-type: "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CacheInterceptor = void 0;
const tslib_1 = require("tslib");
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const decorators_1 = require("../../decorators");
const shared_utils_1 = require("../../utils/shared.utils");
const cache_constants_1 = require("../cache.constants");
const HTTP_ADAPTER_HOST = 'HttpAdapterHost';
const REFLECTOR = 'Reflector';
let CacheInterceptor = class CacheInterceptor {
constructor(cacheManager, reflector) {
this.cacheManager = cacheManager;
this.reflector = reflector;
this.allowedMethods = ['GET'];
}
async intercept(context, next) {
var _a;
const key = this.trackBy(context);
const ttlValueOrFactory = (_a = this.reflector.get(cache_constants_1.CACHE_TTL_METADATA, context.getHandler())) !== null && _a !== void 0 ? _a : null;
if (!key) {
return next.handle();
}
try {
const value = await this.cacheManager.get(key);
if (!shared_utils_1.isNil(value)) {
return rxjs_1.of(value);
}
const ttl = shared_utils_1.isFunction(ttlValueOrFactory)
? await ttlValueOrFactory(context)
: ttlValueOrFactory;
return next.handle().pipe(operators_1.tap(response => {
const args = shared_utils_1.isNil(ttl) ? [key, response] : [key, response, { ttl }];
this.cacheManager.set(...args);
}));
}
catch (_b) {
return next.handle();
}
}
trackBy(context) {
const httpAdapter = this.httpAdapterHost.httpAdapter;
const isHttpApp = httpAdapter && !!httpAdapter.getRequestMethod;
const cacheMetadata = this.reflector.get(cache_constants_1.CACHE_KEY_METADATA, context.getHandler());
if (!isHttpApp || cacheMetadata) {
return cacheMetadata;
}
const request = context.getArgByIndex(0);
if (!this.isRequestCacheable(context)) {
return undefined;
}
return httpAdapter.getRequestUrl(request);
}
isRequestCacheable(context) {
const req = context.switchToHttp().getRequest();
return this.allowedMethods.includes(req.method);
}
};
tslib_1.__decorate([
decorators_1.Optional(),
decorators_1.Inject(HTTP_ADAPTER_HOST),
tslib_1.__metadata("design:type", Object)
], CacheInterceptor.prototype, "httpAdapterHost", void 0);
CacheInterceptor = tslib_1.__decorate([
decorators_1.Injectable(),
tslib_1.__param(0, decorators_1.Inject(cache_constants_1.CACHE_MANAGER)),
tslib_1.__param(1, decorators_1.Inject(REFLECTOR)),
tslib_1.__metadata("design:paramtypes", [Object, Object])
], CacheInterceptor);
exports.CacheInterceptor = CacheInterceptor;
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0053 ]-- |