Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/lib/cache/drivers/dice-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class DiceDbDriver implements CacheDriver {

async get(key: string): Promise<any> {
await this.initializeModules();
const value = await this.client.get(`${this.options.prefix}:::${key}`);
const value = await this.client.get(this.storeKey(key));
if (!value) return null;
try {
return JSON.parse(value);
Expand All @@ -27,7 +27,7 @@ export class DiceDbDriver implements CacheDriver {
): Promise<boolean> {
await this.initializeModules();
try {
const redisKey = `${this.options.prefix}:::${key}`;
const redisKey = this.storeKey(key);
ttlInSec
? await this.client.set(redisKey, JSON.stringify(value), 'EX', ttlInSec)
: await this.client.set(redisKey, JSON.stringify(value));
Expand All @@ -39,7 +39,7 @@ export class DiceDbDriver implements CacheDriver {

async has(key: string): Promise<boolean> {
await this.initializeModules();
const num = await this.client.exists(`${this.options.prefix}:::${key}`);
const num = await this.client.exists(this.storeKey(key));
return !!num;
}

Expand Down
12 changes: 8 additions & 4 deletions packages/core/lib/cache/drivers/inMemory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InMemoryDriver implements CacheDriver {

async get<T>(key: string): Promise<T> {
await this.initialiseModules();
const value = await this.client.get(`${this.options.prefix}:::${key}`);
const value = await this.client.get(this.storeKey(key));
if (!value) return null;
try {
return JSON.parse(value);
Expand All @@ -26,7 +26,7 @@ export class InMemoryDriver implements CacheDriver {
ttlInSec?: number | undefined,
): Promise<boolean> {
await this.initialiseModules();
const cacheKey = `${this.options.prefix}:::${key}`;
const cacheKey = this.storeKey(key);

if (ttlInSec) {
return this.client.set(cacheKey, value, ttlInSec);
Expand All @@ -37,7 +37,7 @@ export class InMemoryDriver implements CacheDriver {

async has(key: string): Promise<boolean> {
await this.initialiseModules();
const cacheKey = `${this.options.prefix}:::${key}`;
const cacheKey = this.storeKey(key);
return this.client.has(cacheKey);
}

Expand Down Expand Up @@ -75,14 +75,18 @@ export class InMemoryDriver implements CacheDriver {
async forget(key: string): Promise<boolean> {
await this.initialiseModules();
try {
const cacheKey = `${this.options.prefix}:::${key}`;
const cacheKey = this.storeKey(key);
await this.client.del(cacheKey);
return true;
} catch {
return false;
}
}

private storeKey(key: string): string {
return `${this.options.prefix}:::${key}`;
}

getClient<T>(): T {
return this.client as unknown as T;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/lib/cache/drivers/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class RedisDriver implements CacheDriver {

async get(key: string): Promise<any> {
await this.initializeModules();
const value = await this.client.get(`${this.options.prefix}:::${key}`);
const value = await this.client.get(this.storeKey(key));
if (!value) return null;
try {
return JSON.parse(value);
Expand All @@ -28,7 +28,7 @@ export class RedisDriver implements CacheDriver {
): Promise<boolean> {
await this.initializeModules();
try {
const redisKey = `${this.options.prefix}:::${key}`;
const redisKey = this.storeKey(key);
ttlInSec
? await this.client.set(redisKey, JSON.stringify(value), 'EX', ttlInSec)
: await this.client.set(redisKey, JSON.stringify(value));
Expand All @@ -40,7 +40,7 @@ export class RedisDriver implements CacheDriver {

async has(key: string): Promise<boolean> {
await this.initializeModules();
const num = await this.client.exists(`${this.options.prefix}:::${key}`);
const num = await this.client.exists(this.storeKey(key));
return !!num;
}

Expand Down
Loading