mirror of
https://github.com/logto-io/logto.git
synced 2025-03-17 22:31:28 -05:00
refactor(core): improve cache behavior (#3706)
This commit is contained in:
parent
d475ef9c03
commit
020a811016
4 changed files with 11 additions and 4 deletions
|
@ -13,6 +13,7 @@ mockEsm('redis', () => ({
|
|||
set: mockFunction,
|
||||
get: mockFunction,
|
||||
del: mockFunction,
|
||||
ping: async () => 'PONG',
|
||||
connect: mockFunction,
|
||||
disconnect: mockFunction,
|
||||
on: mockFunction,
|
||||
|
|
|
@ -40,10 +40,14 @@ export class RedisCache implements CacheStore {
|
|||
async connect() {
|
||||
if (this.client) {
|
||||
await this.client.connect();
|
||||
consoleLog.info('[CACHE] Connected to Redis');
|
||||
} else {
|
||||
consoleLog.warn('[CACHE] No Redis client initialized, skipping');
|
||||
const pong = await this.client.ping();
|
||||
|
||||
if (pong === 'PONG') {
|
||||
consoleLog.info('[CACHE] Connected to Redis');
|
||||
return;
|
||||
}
|
||||
}
|
||||
consoleLog.warn('[CACHE] No Redis client initialized, skipping');
|
||||
}
|
||||
|
||||
async disconnect() {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { type Optional, trySafe } from '@silverhand/essentials';
|
|||
import { type ZodType, z } from 'zod';
|
||||
|
||||
import { type ConnectorWellKnown, connectorWellKnownGuard } from '#src/utils/connectors/types.js';
|
||||
import { consoleLog } from '#src/utils/console.js';
|
||||
|
||||
import { type CacheStore } from './types.js';
|
||||
|
||||
|
@ -172,6 +173,7 @@ export class WellKnownCache {
|
|||
const cachedValue = await trySafe(kvCache.get(type, promiseKey));
|
||||
|
||||
if (cachedValue) {
|
||||
consoleLog.info('[CACHE] Well-known cache hit for', type, promiseKey);
|
||||
return cachedValue;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,5 +44,5 @@ try {
|
|||
consoleLog.error('Error while initializing app:');
|
||||
consoleLog.error(error);
|
||||
|
||||
await Promise.all([trySafe(tenantPool.endAll()), trySafe(redisCache.disconnect())]);
|
||||
void Promise.all([trySafe(tenantPool.endAll()), trySafe(redisCache.disconnect())]);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue