Skip to content

Commit

Permalink
Fix cache storage (#7966)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weiko authored Oct 22, 2024
1 parent 113e9fc commit 6c93587
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import { redisStore } from 'cache-manager-redis-yet';

import { CacheStorageType } from 'src/engine/core-modules/cache-storage/types/cache-storage-type.enum';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service';

export const cacheStorageModuleFactory = (
environmentService: EnvironmentService,
redisClientService: RedisClientService,
): CacheModuleOptions => {
const cacheStorageType = environmentService.get('CACHE_STORAGE_TYPE');
const cacheStorageTtl = environmentService.get('CACHE_STORAGE_TTL');
Expand All @@ -22,10 +20,18 @@ export const cacheStorageModuleFactory = (
return cacheModuleOptions;
}
case CacheStorageType.Redis: {
const redisUrl = environmentService.get('REDIS_URL');

if (!redisUrl) {
throw new Error(
`${cacheStorageType} cache storage requires REDIS_URL to be defined, check your .env file`,
);
}

return {
...cacheModuleOptions,
store: redisStore,
client: redisClientService.getClient(),
url: redisUrl,
};
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { FlushCacheCommand } from 'src/engine/core-modules/cache-storage/command
import { CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-client.service';

@Global()
@Module({
Expand All @@ -16,7 +15,7 @@ import { RedisClientService } from 'src/engine/core-modules/redis-client/redis-c
isGlobal: true,
imports: [ConfigModule],
useFactory: cacheStorageModuleFactory,
inject: [EnvironmentService, RedisClientService],
inject: [EnvironmentService],
}),
],
providers: [
Expand Down

0 comments on commit 6c93587

Please sign in to comment.