mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
Update module for in-mem-cache
This commit is contained in:
parent
bbf42ddaf6
commit
cb1f9c4d72
6 changed files with 49 additions and 4 deletions
|
|
@ -54,6 +54,7 @@ import { SessionScheduler } from '@modules/session/scheduler';
|
|||
import { AuditLogsClearScheduler } from '@modules/audit-logs/scheduler';
|
||||
import { ModulesModule } from '@modules/modules/module';
|
||||
import { EmailListenerModule } from '@modules/email-listener/module';
|
||||
import { InMemoryCacheModule } from '@modules/inMemoryCache/module';
|
||||
export class AppModule implements OnModuleInit {
|
||||
static async register(configs: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
|
||||
// Load static and dynamic modules
|
||||
|
|
@ -115,6 +116,7 @@ export class AppModule implements OnModuleInit {
|
|||
await CrmModule.register(configs),
|
||||
await OrganizationPaymentModule.register(configs),
|
||||
await EmailListenerModule.register(configs),
|
||||
await InMemoryCacheModule.register(configs),
|
||||
];
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import { AppsRepository } from '@modules/apps/repository';
|
|||
import { TooljetDbModule } from '@modules/tooljet-db/module';
|
||||
import { OrganizationRepository } from '@modules/organizations/repository';
|
||||
import { SessionModule } from '@modules/session/module';
|
||||
import { InMemoryCacheService } from '@helpers/in_memory_cache.service';
|
||||
import { SubModule } from '@modules/app/sub-module';
|
||||
import { InMemoryCacheModule } from '@modules/inMemoryCache/module';
|
||||
|
||||
export class DataSourcesModule extends SubModule {
|
||||
static async register(configs?: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
|
||||
|
|
@ -41,6 +41,7 @@ export class DataSourcesModule extends SubModule {
|
|||
await InstanceSettingsModule.register(configs),
|
||||
await TooljetDbModule.register(configs),
|
||||
await SessionModule.register(configs),
|
||||
await InMemoryCacheModule.register(configs),
|
||||
],
|
||||
providers: [
|
||||
DataSourcesService,
|
||||
|
|
@ -54,7 +55,6 @@ export class DataSourcesModule extends SubModule {
|
|||
FeatureAbilityFactory,
|
||||
OrganizationsService,
|
||||
OrganizationRepository,
|
||||
InMemoryCacheService,
|
||||
],
|
||||
controllers: [DataSourcesController],
|
||||
exports: [DataSourcesUtilService, SampleDataSourceService, PluginsServiceSelector],
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import { PluginsServiceSelector } from './services/plugin-selector.service';
|
|||
import { OrganizationConstantsUtilService } from '@modules/organization-constants/util.service';
|
||||
import { DataSourceOptions } from '@entities/data_source_options.entity';
|
||||
import { IDataSourcesUtilService } from './interfaces/IUtilService';
|
||||
import { InMemoryCacheService } from '@helpers/in_memory_cache.service';
|
||||
import { InMemoryCacheService } from '@modules/inMemoryCache/util.service';
|
||||
|
||||
@Injectable()
|
||||
export class DataSourcesUtilService implements IDataSourcesUtilService {
|
||||
|
|
|
|||
27
server/src/modules/inMemoryCache/interfaces/IUtilService.ts
Normal file
27
server/src/modules/inMemoryCache/interfaces/IUtilService.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
export interface ICacheService {
|
||||
/**
|
||||
* Store a promise value in the cache with the given key
|
||||
* @param key - The cache key
|
||||
* @param value - The promise to cache
|
||||
*/
|
||||
set(key: string, value: Promise<any>): void;
|
||||
|
||||
/**
|
||||
* Retrieve a cached promise by key
|
||||
* @param key - The cache key
|
||||
* @returns The cached promise or undefined if not found
|
||||
*/
|
||||
get(key: string): Promise<any> | undefined;
|
||||
|
||||
/**
|
||||
* Check if a key exists in the cache
|
||||
* @param key - The cache key
|
||||
* @returns True if the key exists, false otherwise
|
||||
*/
|
||||
has(key: string): boolean;
|
||||
|
||||
/**
|
||||
* Clear all cached entries
|
||||
*/
|
||||
clear(): void;
|
||||
}
|
||||
15
server/src/modules/inMemoryCache/module.ts
Normal file
15
server/src/modules/inMemoryCache/module.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { SubModule } from '@modules/app/sub-module';
|
||||
import { DynamicModule } from '@nestjs/common';
|
||||
|
||||
export class InMemoryCacheModule extends SubModule {
|
||||
static async register(configs?: { IS_GET_CONTEXT: boolean }): Promise<DynamicModule> {
|
||||
const { InMemoryCacheService } = await this.getProviders(configs, 'inMemoryCache', ['util.service']);
|
||||
|
||||
return {
|
||||
module: InMemoryCacheService,
|
||||
controllers: [],
|
||||
providers: [],
|
||||
exports: [InMemoryCacheService],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ICacheService } from './interfaces/IUtilService';
|
||||
|
||||
@Injectable()
|
||||
export class InMemoryCacheService {
|
||||
export class InMemoryCacheService implements ICacheService {
|
||||
private static cacheStore: Map<string, Promise<any>> = new Map();
|
||||
|
||||
set(key: string, value: Promise<any>): void {
|
||||
Loading…
Reference in a new issue