@ooneex/cache 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -252
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,254 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
21
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
-
else
|
|
23
|
-
for (var i = decorators.length - 1;i >= 0; i--)
|
|
24
|
-
if (d = decorators[i])
|
|
25
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
-
};
|
|
28
|
-
var __legacyMetadataTS = (k, v) => {
|
|
29
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
|
30
|
-
return Reflect.metadata(k, v);
|
|
31
|
-
};
|
|
32
|
-
var __require = import.meta.require;
|
|
2
|
+
var d=Object.create;var{getPrototypeOf:w,defineProperty:y,getOwnPropertyNames:f}=Object;var g=Object.prototype.hasOwnProperty;var x=(e,t,n)=>{n=e!=null?d(w(e)):{};let i=t||!e||!e.__esModule?y(n,"default",{value:e,enumerable:!0}):n;for(let o of f(e))if(!g.call(i,o))y(i,o,{get:()=>e[o],enumerable:!0});return i};var l=function(e,t,n,i){var o=arguments.length,a=o<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,n):i,s;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")a=Reflect.decorate(e,t,n,i);else for(var m=e.length-1;m>=0;m--)if(s=e[m])a=(o<3?s(a):o>3?s(t,n,a):s(t,n))||a;return o>3&&a&&Object.defineProperty(t,n,a),a};var h=(e,t)=>{if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(e,t)};var C=import.meta.require;import{Exception as T}from"@ooneex/exception";import{HttpStatus as b}from"@ooneex/http-status";class r extends T{constructor(e,t={}){super(e,{status:b.Code.InternalServerError,data:t});this.name="CacheException"}}import{container as E,EContainerScope as v}from"@ooneex/container";var c={cache:(e=v.Singleton)=>{return(t)=>{E.add(t,e)}}};class u{cacheDir;maxFileSize;constructor(e={}){this.cacheDir=e.cacheDir||`${process.cwd()}/.cache`,this.maxFileSize=e.maxFileSize||10485760}async connect(){try{let{mkdir:e,stat:t}=await import("fs/promises");if(await e(this.cacheDir,{recursive:!0}),!(await t(this.cacheDir)).isDirectory())throw new r("Failed to create cache directory")}catch(e){throw new r(`Failed to initialize filesystem cache: ${e}`)}}async get(e){try{return await this.connect(),(await this.readCacheEntry(e))?.value}catch(t){throw new r(`Failed to get key "${e}": ${t}`)}}async set(e,t,n){try{await this.connect();let i={value:t,createdAt:Date.now(),originalKey:e,...n!==void 0&&{ttl:n}};await this.writeCacheEntry(e,i)}catch(i){throw new r(`Failed to set key "${e}": ${i}`)}}async delete(e){try{await this.connect();let t=Bun.file(this.getFilePath(e));if(!await t.exists())return!1;return await t.delete(),!0}catch(t){throw new r(`Failed to delete key "${e}": ${t}`)}}async has(e){try{return await this.connect(),await this.readCacheEntry(e)!==void 0}catch(t){throw new r(`Failed to check if key "${e}" exists: ${t}`)}}getFilePath(e){if(e.length>200){let n=Bun.hash(e);return`${this.cacheDir}/${n.toString(36)}.cache`}let t=e.replace(/[<>:"/\\|?*\x00-\x1f]/g,"_");return`${this.cacheDir}/${t}.cache`}isExpired(e){if(!e.ttl)return!1;if(e.ttl===0)return!1;return e.createdAt+e.ttl*1000<Date.now()}async readCacheEntry(e){try{let t=Bun.file(this.getFilePath(e));if(!await t.exists())return;let n=await t.text(),i=JSON.parse(n);if(this.isExpired(i)){await t.delete().catch(()=>{});return}return i}catch{return}}async writeCacheEntry(e,t){let n=JSON.stringify(t);if(Buffer.byteLength(n,"utf-8")>this.maxFileSize)throw new r(`Cache entry exceeds maximum file size of ${this.maxFileSize} bytes`);await Bun.write(this.getFilePath(e),n)}}u=l([c.cache(),h("design:paramtypes",[typeof FilesystemCacheOptionsType==="undefined"?Object:FilesystemCacheOptionsType])],u);class p{client;constructor(e={}){let t=e.connectionString||Bun.env.CACHE_REDIS_URL;if(!t)throw new r("Redis connection string is required. Please provide a connection string either through the constructor options or set the CACHE_REDIS_URL environment variable.");let{connectionString:n,...i}=e,a={...{connectionTimeout:1e4,idleTimeout:30000,autoReconnect:!0,maxRetries:3,enableOfflineQueue:!0,enableAutoPipelining:!0},...i};this.client=new Bun.RedisClient(t,a)}async connect(){if(!this.client.connected)await this.client.connect()}async get(e){try{await this.connect();let t=await this.client.get(e);if(t===null)return;try{return JSON.parse(t)}catch{return t}}catch(t){throw new r(`Failed to get key "${e}": ${t}`)}}async set(e,t,n){try{await this.connect();let i=t===void 0?null:t,o=typeof i==="string"?i:JSON.stringify(i);if(await this.client.set(e,o),n&&n>0)await this.client.expire(e,n)}catch(i){throw new r(`Failed to set key "${e}": ${i}`)}}async delete(e){try{return await this.connect(),await this.client.del(e)>0}catch(t){throw new r(`Failed to delete key "${e}": ${t}`)}}async has(e){try{return await this.connect(),await this.client.exists(e)}catch(t){throw new r(`Failed to check if key "${e}" exists: ${t}`)}}}p=l([c.cache(),h("design:paramtypes",[typeof RedisCacheOptionsType==="undefined"?Object:RedisCacheOptionsType])],p);export{c as decorator,p as RedisCache,u as FilesystemCache,r as CacheException};
|
|
33
3
|
|
|
34
|
-
|
|
35
|
-
import { Exception } from "@ooneex/exception";
|
|
36
|
-
import { HttpStatus } from "@ooneex/http-status";
|
|
37
|
-
|
|
38
|
-
class CacheException extends Exception {
|
|
39
|
-
constructor(message, data = {}) {
|
|
40
|
-
super(message, {
|
|
41
|
-
status: HttpStatus.Code.InternalServerError,
|
|
42
|
-
data
|
|
43
|
-
});
|
|
44
|
-
this.name = "CacheException";
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// src/decorators.ts
|
|
48
|
-
import { container, EContainerScope } from "@ooneex/container";
|
|
49
|
-
var decorator = {
|
|
50
|
-
cache: (scope = EContainerScope.Singleton) => {
|
|
51
|
-
return (target) => {
|
|
52
|
-
container.add(target, scope);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
// src/FilesystemCache.ts
|
|
57
|
-
class FilesystemCache {
|
|
58
|
-
cacheDir;
|
|
59
|
-
maxFileSize;
|
|
60
|
-
constructor(options = {}) {
|
|
61
|
-
this.cacheDir = options.cacheDir || `${process.cwd()}/.cache`;
|
|
62
|
-
this.maxFileSize = options.maxFileSize || 10 * 1024 * 1024;
|
|
63
|
-
}
|
|
64
|
-
async connect() {
|
|
65
|
-
try {
|
|
66
|
-
const { mkdir, stat } = await import("fs/promises");
|
|
67
|
-
await mkdir(this.cacheDir, { recursive: true });
|
|
68
|
-
const stats = await stat(this.cacheDir);
|
|
69
|
-
if (!stats.isDirectory()) {
|
|
70
|
-
throw new CacheException("Failed to create cache directory");
|
|
71
|
-
}
|
|
72
|
-
} catch (error) {
|
|
73
|
-
throw new CacheException(`Failed to initialize filesystem cache: ${error}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async get(key) {
|
|
77
|
-
try {
|
|
78
|
-
await this.connect();
|
|
79
|
-
const entry = await this.readCacheEntry(key);
|
|
80
|
-
return entry?.value;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
throw new CacheException(`Failed to get key "${key}": ${error}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
async set(key, value, ttl) {
|
|
86
|
-
try {
|
|
87
|
-
await this.connect();
|
|
88
|
-
const entry = {
|
|
89
|
-
value,
|
|
90
|
-
createdAt: Date.now(),
|
|
91
|
-
originalKey: key,
|
|
92
|
-
...ttl !== undefined && { ttl }
|
|
93
|
-
};
|
|
94
|
-
await this.writeCacheEntry(key, entry);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
throw new CacheException(`Failed to set key "${key}": ${error}`);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async delete(key) {
|
|
100
|
-
try {
|
|
101
|
-
await this.connect();
|
|
102
|
-
const file = Bun.file(this.getFilePath(key));
|
|
103
|
-
if (!await file.exists()) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
await file.delete();
|
|
107
|
-
return true;
|
|
108
|
-
} catch (error) {
|
|
109
|
-
throw new CacheException(`Failed to delete key "${key}": ${error}`);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async has(key) {
|
|
113
|
-
try {
|
|
114
|
-
await this.connect();
|
|
115
|
-
const entry = await this.readCacheEntry(key);
|
|
116
|
-
return entry !== undefined;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
throw new CacheException(`Failed to check if key "${key}" exists: ${error}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
getFilePath(key) {
|
|
122
|
-
if (key.length > 200) {
|
|
123
|
-
const hash = Bun.hash(key);
|
|
124
|
-
return `${this.cacheDir}/${hash.toString(36)}.cache`;
|
|
125
|
-
}
|
|
126
|
-
const sanitizedKey = key.replace(/[<>:"/\\|?*\x00-\x1f]/g, "_");
|
|
127
|
-
return `${this.cacheDir}/${sanitizedKey}.cache`;
|
|
128
|
-
}
|
|
129
|
-
isExpired(entry) {
|
|
130
|
-
if (!entry.ttl)
|
|
131
|
-
return false;
|
|
132
|
-
if (entry.ttl === 0) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
return entry.createdAt + entry.ttl * 1000 < Date.now();
|
|
136
|
-
}
|
|
137
|
-
async readCacheEntry(key) {
|
|
138
|
-
try {
|
|
139
|
-
const file = Bun.file(this.getFilePath(key));
|
|
140
|
-
if (!await file.exists()) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const content = await file.text();
|
|
144
|
-
const entry = JSON.parse(content);
|
|
145
|
-
if (this.isExpired(entry)) {
|
|
146
|
-
await file.delete().catch(() => {});
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
return entry;
|
|
150
|
-
} catch {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
async writeCacheEntry(key, entry) {
|
|
155
|
-
const content = JSON.stringify(entry);
|
|
156
|
-
if (Buffer.byteLength(content, "utf-8") > this.maxFileSize) {
|
|
157
|
-
throw new CacheException(`Cache entry exceeds maximum file size of ${this.maxFileSize} bytes`);
|
|
158
|
-
}
|
|
159
|
-
await Bun.write(this.getFilePath(key), content);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
FilesystemCache = __legacyDecorateClassTS([
|
|
163
|
-
decorator.cache(),
|
|
164
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
165
|
-
typeof FilesystemCacheOptionsType === "undefined" ? Object : FilesystemCacheOptionsType
|
|
166
|
-
])
|
|
167
|
-
], FilesystemCache);
|
|
168
|
-
// src/RedisCache.ts
|
|
169
|
-
class RedisCache {
|
|
170
|
-
client;
|
|
171
|
-
constructor(options = {}) {
|
|
172
|
-
const connectionString = options.connectionString || Bun.env.CACHE_REDIS_URL;
|
|
173
|
-
if (!connectionString) {
|
|
174
|
-
throw new CacheException("Redis connection string is required. Please provide a connection string either through the constructor options or set the CACHE_REDIS_URL environment variable.");
|
|
175
|
-
}
|
|
176
|
-
const { connectionString: _, ...userOptions } = options;
|
|
177
|
-
const defaultOptions = {
|
|
178
|
-
connectionTimeout: 1e4,
|
|
179
|
-
idleTimeout: 30000,
|
|
180
|
-
autoReconnect: true,
|
|
181
|
-
maxRetries: 3,
|
|
182
|
-
enableOfflineQueue: true,
|
|
183
|
-
enableAutoPipelining: true
|
|
184
|
-
};
|
|
185
|
-
const clientOptions = { ...defaultOptions, ...userOptions };
|
|
186
|
-
this.client = new Bun.RedisClient(connectionString, clientOptions);
|
|
187
|
-
}
|
|
188
|
-
async connect() {
|
|
189
|
-
if (!this.client.connected) {
|
|
190
|
-
await this.client.connect();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async get(key) {
|
|
194
|
-
try {
|
|
195
|
-
await this.connect();
|
|
196
|
-
const value = await this.client.get(key);
|
|
197
|
-
if (value === null) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
return JSON.parse(value);
|
|
202
|
-
} catch {
|
|
203
|
-
return value;
|
|
204
|
-
}
|
|
205
|
-
} catch (error) {
|
|
206
|
-
throw new CacheException(`Failed to get key "${key}": ${error}`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
async set(key, value, ttl) {
|
|
210
|
-
try {
|
|
211
|
-
await this.connect();
|
|
212
|
-
const normalizedValue = value === undefined ? null : value;
|
|
213
|
-
const serializedValue = typeof normalizedValue === "string" ? normalizedValue : JSON.stringify(normalizedValue);
|
|
214
|
-
await this.client.set(key, serializedValue);
|
|
215
|
-
if (ttl && ttl > 0) {
|
|
216
|
-
await this.client.expire(key, ttl);
|
|
217
|
-
}
|
|
218
|
-
} catch (error) {
|
|
219
|
-
throw new CacheException(`Failed to set key "${key}": ${error}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async delete(key) {
|
|
223
|
-
try {
|
|
224
|
-
await this.connect();
|
|
225
|
-
const result = await this.client.del(key);
|
|
226
|
-
return result > 0;
|
|
227
|
-
} catch (error) {
|
|
228
|
-
throw new CacheException(`Failed to delete key "${key}": ${error}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async has(key) {
|
|
232
|
-
try {
|
|
233
|
-
await this.connect();
|
|
234
|
-
const result = await this.client.exists(key);
|
|
235
|
-
return result;
|
|
236
|
-
} catch (error) {
|
|
237
|
-
throw new CacheException(`Failed to check if key "${key}" exists: ${error}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
RedisCache = __legacyDecorateClassTS([
|
|
242
|
-
decorator.cache(),
|
|
243
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
244
|
-
typeof RedisCacheOptionsType === "undefined" ? Object : RedisCacheOptionsType
|
|
245
|
-
])
|
|
246
|
-
], RedisCache);
|
|
247
|
-
export {
|
|
248
|
-
decorator,
|
|
249
|
-
RedisCache,
|
|
250
|
-
FilesystemCache,
|
|
251
|
-
CacheException
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
//# debugId=AC71E686C6C533DF64756E2164756E21
|
|
4
|
+
//# debugId=F7CD22D06BDF672A64756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"import { CacheException } from \"./CacheException\";\nimport { decorator } from \"./decorators\";\nimport type { FilesystemCacheOptionsType, ICache } from \"./types\";\n\ntype CacheEntryType<T = unknown> = {\n value: T;\n ttl?: number;\n createdAt: number;\n originalKey: string;\n};\n\n@decorator.cache()\nexport class FilesystemCache implements ICache {\n private cacheDir: string;\n private maxFileSize: number;\n\n constructor(options: FilesystemCacheOptionsType = {}) {\n this.cacheDir = options.cacheDir || `${process.cwd()}/.cache`;\n this.maxFileSize = options.maxFileSize || 10 * 1024 * 1024; // 10MB default\n }\n\n private async connect(): Promise<void> {\n try {\n const { mkdir, stat } = await import(\"node:fs/promises\");\n await mkdir(this.cacheDir, { recursive: true });\n\n const stats = await stat(this.cacheDir);\n if (!stats.isDirectory()) {\n throw new CacheException(\"Failed to create cache directory\");\n }\n } catch (error) {\n throw new CacheException(`Failed to initialize filesystem cache: ${error}`);\n }\n }\n\n public async get<T = unknown>(key: string): Promise<T | undefined> {\n try {\n await this.connect();\n const entry = await this.readCacheEntry<T>(key);\n\n return entry?.value;\n } catch (error) {\n throw new CacheException(`Failed to get key \"${key}\": ${error}`);\n }\n }\n\n public async set<T = unknown>(key: string, value: T, ttl?: number): Promise<void> {\n try {\n await this.connect();\n\n const entry: CacheEntryType<T> = {\n value,\n createdAt: Date.now(),\n originalKey: key,\n ...(ttl !== undefined && { ttl }),\n };\n\n await this.writeCacheEntry(key, entry);\n } catch (error) {\n throw new CacheException(`Failed to set key \"${key}\": ${error}`);\n }\n }\n\n public async delete(key: string): Promise<boolean> {\n try {\n await this.connect();\n\n const file = Bun.file(this.getFilePath(key));\n\n if (!(await file.exists())) {\n return false;\n }\n\n await file.delete();\n\n return true;\n } catch (error) {\n throw new CacheException(`Failed to delete key \"${key}\": ${error}`);\n }\n }\n\n public async has(key: string): Promise<boolean> {\n try {\n await this.connect();\n const entry = await this.readCacheEntry(key);\n\n return entry !== undefined;\n } catch (error) {\n throw new CacheException(`Failed to check if key \"${key}\" exists: ${error}`);\n }\n }\n\n private getFilePath(key: string): string {\n if (key.length > 200) {\n const hash = Bun.hash(key);\n return `${this.cacheDir}/${hash.toString(36)}.cache`;\n }\n\n const sanitizedKey = key.replace(/[<>:\"/\\\\|?*\\x00-\\x1f]/g, \"_\");\n\n return `${this.cacheDir}/${sanitizedKey}.cache`;\n }\n\n private isExpired(entry: CacheEntryType): boolean {\n if (!entry.ttl) return false;\n\n if (entry.ttl === 0) {\n return false;\n }\n\n return entry.createdAt + entry.ttl * 1000 < Date.now();\n }\n\n private async readCacheEntry<T>(key: string): Promise<CacheEntryType<T> | undefined> {\n try {\n const file = Bun.file(this.getFilePath(key));\n\n if (!(await file.exists())) {\n return;\n }\n\n const content = await file.text();\n const entry: CacheEntryType<T> = JSON.parse(content);\n\n if (this.isExpired(entry)) {\n await file.delete().catch(() => {});\n return;\n }\n\n return entry;\n } catch {\n return;\n }\n }\n\n private async writeCacheEntry<T>(key: string, entry: CacheEntryType<T>): Promise<void> {\n const content = JSON.stringify(entry);\n\n if (Buffer.byteLength(content, \"utf-8\") > this.maxFileSize) {\n throw new CacheException(`Cache entry exceeds maximum file size of ${this.maxFileSize} bytes`);\n }\n\n await Bun.write(this.getFilePath(key), content);\n }\n}\n",
|
|
8
8
|
"import { CacheException } from \"./CacheException\";\nimport { decorator } from \"./decorators\";\nimport type { ICache, RedisCacheOptionsType } from \"./types\";\n\n@decorator.cache()\nexport class RedisCache implements ICache {\n private client: Bun.RedisClient;\n\n constructor(options: RedisCacheOptionsType = {}) {\n const connectionString = options.connectionString || Bun.env.CACHE_REDIS_URL;\n\n if (!connectionString) {\n throw new CacheException(\n \"Redis connection string is required. Please provide a connection string either through the constructor options or set the CACHE_REDIS_URL environment variable.\",\n );\n }\n\n const { connectionString: _, ...userOptions } = options;\n\n const defaultOptions = {\n connectionTimeout: 10_000,\n idleTimeout: 30_000,\n autoReconnect: true,\n maxRetries: 3,\n enableOfflineQueue: true,\n enableAutoPipelining: true,\n };\n\n const clientOptions = { ...defaultOptions, ...userOptions };\n\n this.client = new Bun.RedisClient(connectionString, clientOptions);\n }\n\n private async connect(): Promise<void> {\n if (!this.client.connected) {\n await this.client.connect();\n }\n }\n\n public async get<T = unknown>(key: string): Promise<T | undefined> {\n try {\n await this.connect();\n const value = await this.client.get(key);\n\n if (value === null) {\n return;\n }\n\n try {\n return JSON.parse(value);\n } catch {\n return value as T;\n }\n } catch (error) {\n throw new CacheException(`Failed to get key \"${key}\": ${error}`);\n }\n }\n\n public async set<T = unknown>(key: string, value: T, ttl?: number): Promise<void> {\n try {\n await this.connect();\n\n const normalizedValue = value === undefined ? null : value;\n const serializedValue = typeof normalizedValue === \"string\" ? normalizedValue : JSON.stringify(normalizedValue);\n\n await this.client.set(key, serializedValue);\n\n if (ttl && ttl > 0) {\n await this.client.expire(key, ttl);\n }\n } catch (error) {\n throw new CacheException(`Failed to set key \"${key}\": ${error}`);\n }\n }\n\n public async delete(key: string): Promise<boolean> {\n try {\n await this.connect();\n const result = await this.client.del(key);\n\n return result > 0;\n } catch (error) {\n throw new CacheException(`Failed to delete key \"${key}\": ${error}`);\n }\n }\n\n public async has(key: string): Promise<boolean> {\n try {\n await this.connect();\n const result = await this.client.exists(key);\n\n return result;\n } catch (error) {\n throw new CacheException(`Failed to check if key \"${key}\" exists: ${error}`);\n }\n }\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";0wBAAA,oBAAS,0BACT,qBAAS,4BAEF,MAAM,UAAuB,CAAU,CAC5C,WAAW,CAAC,EAAiB,EAAgC,CAAC,EAAG,CAC/D,MAAM,EAAS,CACb,OAAQ,EAAW,KAAK,oBACxB,MACF,CAAC,EACD,KAAK,KAAO,iBAEhB,CCXA,oBAAS,qBAAW,0BAGb,IAAM,EAAY,CACvB,MAAO,CAAC,EAAyB,EAAgB,YAAc,CAC7D,MAAO,CAAC,IAAiC,CACvC,EAAU,IAAI,EAAQ,CAAK,GAGjC,ECGO,MAAM,CAAkC,CACrC,SACA,YAER,WAAW,CAAC,EAAsC,CAAC,EAAG,CACpD,KAAK,SAAW,EAAQ,UAAY,GAAG,QAAQ,IAAI,WACnD,KAAK,YAAc,EAAQ,aAAe,cAG9B,QAAO,EAAkB,CACrC,GAAI,CACF,IAAQ,QAAO,QAAS,KAAa,uBAIrC,GAHA,MAAM,EAAM,KAAK,SAAU,CAAE,UAAW,EAAK,CAAC,EAG1C,EADU,MAAM,EAAK,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