channel-cache.service.ts 853 B

1234567891011121314151617181920212223242526
  1. import { Injectable } from '@nestjs/common';
  2. import { BaseCacheService } from '@box/common/cache/cache-service';
  3. import { tsCacheKeys } from '@box/common/cache/ts-cache-key.provider';
  4. import { ChannelCachePayload } from './channel-cache.builder';
  5. import { RedisService } from '@box/db/redis/redis.service';
  6. @Injectable()
  7. export class ChannelCacheService extends BaseCacheService {
  8. constructor(redis: RedisService) {
  9. super(redis, ChannelCacheService.name);
  10. }
  11. async getAllChannels(): Promise<ChannelCachePayload[]> {
  12. return (
  13. (await this.getJson<ChannelCachePayload[]>(tsCacheKeys.channel.all())) ?? []
  14. );
  15. }
  16. async getChannelById(id: string): Promise<ChannelCachePayload | null> {
  17. if (!id) return null;
  18. return (
  19. (await this.getJson<ChannelCachePayload>(tsCacheKeys.channel.byId(id))) ??
  20. null
  21. );
  22. }
  23. }