@ivfuture/ecomm-cache-redis
Advanced tools
Comparing version 1.58.0 to 1.58.1
@@ -1,15 +0,18 @@ | ||
import { ICacheService } from "@ivfuture/ecomm-types"; | ||
import { Redis } from "ioredis"; | ||
import Redis from "ioredis"; | ||
import { AbstractCacheService, ConfigModule } from "@ivfuture/ecomm-core"; | ||
import { Logger } from "@ivfuture/ecomm-types"; | ||
import { RedisCacheModuleOptions } from "../types"; | ||
type InjectedDependencies = { | ||
cacheRedisConnection: Redis; | ||
configModule: ConfigModule; | ||
logger: Logger; | ||
}; | ||
declare class RedisCacheService implements ICacheService { | ||
declare class RedisCacheService extends AbstractCacheService { | ||
protected readonly redis: Redis; | ||
protected readonly logger_: Logger; | ||
protected readonly TTL: number; | ||
protected readonly redis: Redis; | ||
private readonly namespace; | ||
constructor({ cacheRedisConnection }: InjectedDependencies, options?: RedisCacheModuleOptions); | ||
protected readonly namespace: string; | ||
constructor({ configModule, logger }: InjectedDependencies, options?: RedisCacheModuleOptions); | ||
/** | ||
* Set a key/value pair to the cache. | ||
* If the ttl is 0 it will act like the value should not be cached at all. | ||
* If the ttl is 0, it will act like the value should not be cached at all. | ||
* @param key | ||
@@ -26,3 +29,3 @@ * @param data | ||
/** | ||
* Invalidate cache for a specific key. a key can be either a specific key or more global such as "ps:*". | ||
* Invalidate cache for a specific key. A key can be either a specific key or a pattern like "ps:*". | ||
* @param key | ||
@@ -35,4 +38,4 @@ */ | ||
*/ | ||
private getCacheKey; | ||
protected getCacheKey(key: string): string; | ||
} | ||
export default RedisCacheService; |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,19 +64,48 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DEFAULT_NAMESPACE = "medusa"; | ||
var DEFAULT_CACHE_TIME = 30; // 30 seconds | ||
var EXPIRY_MODE = "EX"; // "EX" stands for an expiry time in second | ||
var RedisCacheService = /** @class */ (function () { | ||
var ioredis_1 = __importDefault(require("ioredis")); | ||
var ecomm_core_1 = require("@ivfuture/ecomm-core"); | ||
var EXPIRY_MODE = "EX"; // "EX" stands for an expiry time in seconds | ||
var DEFAULT_NAMESPACE = "ezier"; | ||
var DEFAULT_CACHE_TIME = 30; | ||
var redisInstance = null; | ||
var RedisCacheService = /** @class */ (function (_super) { | ||
__extends(RedisCacheService, _super); | ||
function RedisCacheService(_a, options) { | ||
var cacheRedisConnection = _a.cacheRedisConnection; | ||
var configModule = _a.configModule, logger = _a.logger; | ||
if (options === void 0) { options = {}; } | ||
var _b; | ||
this.redis = cacheRedisConnection; | ||
this.TTL = (_b = options.ttl) !== null && _b !== void 0 ? _b : DEFAULT_CACHE_TIME; | ||
this.namespace = | ||
"".concat(this.constructor.name, ":") + options.namespace || DEFAULT_NAMESPACE; | ||
var _b, _c, _d, _e; | ||
// eslint-disable-next-line prefer-rest-params | ||
var _this = _super.call(this, arguments[0]) || this; | ||
_this.logger_ = logger; | ||
// Initialize Redis instance if not already created | ||
if (!redisInstance) { | ||
var redisUrl = (_b = options.redisUrl) !== null && _b !== void 0 ? _b : configModule.projectConfig.redis_url; | ||
var redisOptions = (_c = options.redisOptions) !== null && _c !== void 0 ? _c : {}; | ||
if (!redisUrl) { | ||
throw Error("No `redisUrl` provided in `cacheService` module options. It is required for the Redis Cache Module."); | ||
} | ||
redisInstance = new ioredis_1.default(redisUrl, __assign({ | ||
// Lazy connect to properly handle connection errors | ||
lazyConnect: true }, redisOptions)); | ||
redisInstance | ||
.connect() | ||
.then(function () { | ||
logger.info("Connection to Redis in module 'cache-redis' established"); | ||
}) | ||
.catch(function (err) { | ||
logger.error("An error occurred while connecting to Redis in module 'cache-redis'", err); | ||
}); | ||
} | ||
_this.redis = redisInstance; | ||
_this.TTL = (_d = options.ttl) !== null && _d !== void 0 ? _d : DEFAULT_CACHE_TIME; | ||
_this.namespace = "".concat(_this.constructor.name, ":").concat((_e = options.namespace) !== null && _e !== void 0 ? _e : DEFAULT_NAMESPACE); | ||
return _this; | ||
} | ||
/** | ||
* Set a key/value pair to the cache. | ||
* If the ttl is 0 it will act like the value should not be cached at all. | ||
* If the ttl is 0, it will act like the value should not be cached at all. | ||
* @param key | ||
@@ -106,3 +161,3 @@ * @param data | ||
/** | ||
* Invalidate cache for a specific key. a key can be either a specific key or more global such as "ps:*". | ||
* Invalidate cache for a specific key. A key can be either a specific key or a pattern like "ps:*". | ||
* @param key | ||
@@ -138,4 +193,4 @@ */ | ||
return RedisCacheService; | ||
}()); | ||
}(ecomm_core_1.AbstractCacheService)); | ||
exports.default = RedisCacheService; | ||
//# sourceMappingURL=redis-cache.js.map |
{ | ||
"name": "@ivfuture/ecomm-cache-redis", | ||
"version": "1.58.0", | ||
"version": "1.58.1", | ||
"description": "Redis Cache Module for Medusa", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@ivfuture/ecomm-types": "1.58.0", | ||
"@ivfuture/ecomm-types": "1.58.1", | ||
"cross-env": "^7.0.3", | ||
@@ -36,7 +36,7 @@ "jest": "^29.7.0", | ||
"dependencies": { | ||
"@ivfuture/ecomm-modules-sdk": "1.58.0", | ||
"@ivfuture/ecomm-core": "2.70.1", | ||
"awilix": "^8.0.0", | ||
"ioredis": "^5.3.1" | ||
}, | ||
"gitHead": "0316a5b6db8ac9d784488999e6b3a804ae62858e" | ||
"gitHead": "51656d6161670cd5fc2d90974cc5f2cf41fd097b" | ||
} |
Sorry, the diff of this file is not supported yet
17132
12
265
+ Added@ivfuture/ecomm-core@2.70.1
- Removed@ivfuture/ecomm-modules-sdk@1.58.0