0
Fork 0
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:
Gao Sun 2023-04-18 12:20:07 +08:00 committed by GitHub
parent d475ef9c03
commit 020a811016
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View file

@ -13,6 +13,7 @@ mockEsm('redis', () => ({
set: mockFunction,
get: mockFunction,
del: mockFunction,
ping: async () => 'PONG',
connect: mockFunction,
disconnect: mockFunction,
on: mockFunction,

View file

@ -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() {

View file

@ -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;
}

View file

@ -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())]);
}