remove unused modules
This commit is contained in:
@@ -9,15 +9,12 @@ import { AdminModule } from './modules/admin/admin.module';
|
||||
import { ThrottlerModule } from '@nestjs/throttler';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { cacheConfig } from './config/cache.config';
|
||||
import { BusinessModule } from './modules/business/business.module';
|
||||
import { CatalogueModule } from './modules/catalogue/catalogue.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true, cache: true }),
|
||||
CacheModule.registerAsync(cacheConfig()),
|
||||
MikroOrmModule.forRootAsync(dataBaseConfig),
|
||||
UtilsModule,
|
||||
AuthModule,
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Keyv } from 'keyv';
|
||||
import KeyvRedis from '@keyv/redis';
|
||||
import type { CacheModuleAsyncOptions } from '@nestjs/cache-manager';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { CacheableMemory } from 'cacheable';
|
||||
|
||||
export function cacheConfig(): CacheModuleAsyncOptions {
|
||||
return {
|
||||
isGlobal: true,
|
||||
inject: [ConfigService],
|
||||
useFactory: async (configService: ConfigService) => {
|
||||
const redisUri = configService.get('REDIS_URI');
|
||||
const namespace = configService.get('CACHE_NAMESPACE', 'app-cache');
|
||||
const ttl = +configService.get<number>('CACHE_TTL', 3600); //1 hour
|
||||
|
||||
return {
|
||||
stores: [
|
||||
new Keyv({
|
||||
store: new CacheableMemory({ ttl: ttl * 1000, lruSize: 5000 }),
|
||||
namespace: namespace
|
||||
}),
|
||||
new KeyvRedis(redisUri, { namespace: namespace }),
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
import { CACHE_MANAGER, Cache } from '@nestjs/cache-manager';
|
||||
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class CacheService implements OnModuleInit {
|
||||
private readonly logger = new Logger(CacheService.name);
|
||||
|
||||
constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}
|
||||
|
||||
async onModuleInit() {
|
||||
;
|
||||
this.logger.log(`Active Cache Store: ${JSON.stringify(this.cacheManager as any)}`);
|
||||
|
||||
// Should log 'Keyv' or 'KeyvRedis'. If it says 'Memory', the config is still wrong.
|
||||
this.logger.log('Pinging Redis to check connection...');
|
||||
try {
|
||||
await this.set('ping', 'pong', 10); // TTL in seconds
|
||||
const result = await this.get('ping');
|
||||
|
||||
if (result === 'pong') {
|
||||
this.logger.log('✅ Redis connection successful (set/get test passed).');
|
||||
} else {
|
||||
this.logger.error(`❌ Redis connection test failed. Expected 'pong', got '${result}'.`);
|
||||
}
|
||||
|
||||
await this.del('ping');
|
||||
} catch (error: any) {
|
||||
this.logger.error('❌ Failed to connect to Redis during ping test:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get value from cache */
|
||||
async get<T>(key: string): Promise<T | undefined> {
|
||||
return await this.cacheManager.get<T>(key);
|
||||
}
|
||||
|
||||
/** Set value in cache with TTL in seconds */
|
||||
async set(key: string, value: any, ttlSeconds: number) {
|
||||
// cache-manager expects TTL in seconds
|
||||
await this.cacheManager.set(key, value, ttlSeconds * 1000);
|
||||
}
|
||||
|
||||
/** Delete a key from cache */
|
||||
async del(key: string) {
|
||||
await this.cacheManager.del(key);
|
||||
}
|
||||
|
||||
/** Get remaining TTL in seconds */
|
||||
async getTtl(key: string): Promise<number | undefined> {
|
||||
return await this.cacheManager.ttl(key);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { CacheService } from './cache.service';
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [],
|
||||
providers: [CacheService, ],
|
||||
exports: [CacheService],
|
||||
providers: [ ],
|
||||
exports: [],
|
||||
})
|
||||
export class UtilsModule {}
|
||||
|
||||
Reference in New Issue
Block a user