UNPKG

nest-api-cache

Version:

使用redis实现nestjs接口层面的缓存

32 lines (31 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NestCacheApi = void 0; /* * @Description: 自定义装饰器,如果该接口需要走redis缓存就加上去 * @Author: 水痕 * @Github: https://github.com/kuangshp * @Email: 332904234@qq.com * @Company: * @Date: 2021-03-09 15:47:06 * @LastEditors: 水痕 * @LastEditTime: 2021-04-25 14:01:00 * @FilePath: /nest-api-cache/src/decorators/nest.cache.api.ts */ const common_1 = require("@nestjs/common"); const constants_1 = require("../constants"); const redisCache_config_1 = require("../config/redisCache.config"); // 是否缓存 const isCache = true; /** * @Author: 水痕 * @Date: 2021-03-09 17:05:19 * @LastEditors: 水痕 * @Description: 自定义装饰器,用于路由上装饰需要缓存的接口 * @param {number} exSecond redis缓存过期时间,时间为妙 * @return {*} */ function NestCacheApi(exSecond = redisCache_config_1.default.redisEXSecond) { return common_1.applyDecorators(common_1.SetMetadata(constants_1.REDIS_CACHE_KEY, isCache), common_1.SetMetadata(constants_1.REDIS_CACHE_EX_SECOND_KEY, exSecond)); } exports.NestCacheApi = NestCacheApi;