// libs/common/src/cache/cache-keys.ts import type { AdType } from '../ads/ad-types'; /** * Video sort key type for video listing and pooling. */ export type VideoSortKey = 'latest' | 'popular' | 'manual'; /** * Video home section key type for home page sections. */ export type VideoHomeSectionKey = 'featured' | 'latest' | 'editorPick'; /** * Centralized Redis logical keys (without REDIS_KEY_PREFIX). * Actual keys in Redis will be: * e.g. "box:" + "app:channel:all" => "box:app:channel:all" */ export const CacheKeys = { // ───────────────────────────────────────────── // CHANNELS (existing) // ───────────────────────────────────────────── appChannelAll: 'app:channel:all', appChannelById: (channelId: string | number): string => `app:channel:by-id:${channelId}`, // NEW: Channel → Categories tree (future use) appChannelWithCategories: (channelId: string | number): string => `app:channel:with-categories:${channelId}`, // ───────────────────────────────────────────── // CATEGORIES (existing) // ───────────────────────────────────────────── appCategory: (categoryId: string | number): string => `app:category:${categoryId}`, appCategoryAll: 'app:category:all', appCategoryById: (categoryId: string | number): string => `app:category:by-id:${categoryId}`, // NEW: Category → Tags tree (main for video listing) appCategoryWithTags: (categoryId: string | number): string => `app:category:with-tags:${categoryId}`, // ───────────────────────────────────────────── // TAGS (new) // ───────────────────────────────────────────── // Global tag suggestion pool appTagAll: 'app:tag:all', // (Optional future) // appTagByCategory: (categoryId: string | number): string => // `app:tag:by-category:${categoryId}`, // appTagByChannel: (channelId: string | number): string => // `app:tag:by-channel:${channelId}`, // ───────────────────────────────────────────── // ADS (existing) // ───────────────────────────────────────────── appAdById: (adId: string | number): string => `app:ad:by-id:${adId}`, // ───────────────────────────────────────────── // AD POOLS (AdType-based) // ───────────────────────────────────────────── /** Build the canonical ad pool key for a given AdType. */ appAdPoolByType: (adType: AdType | string): string => `app:adpool:${adType}`, // ───────────────────────────────────────────── // VIDEO LISTS (existing) // ───────────────────────────────────────────── appHomeVideoPage: (page: number): string => `app:videolist:home:page:${page}`, appChannelVideoPage: (channelId: string | number, page: number): string => `app:videolist:channel:${channelId}:page:${page}`, appTrendingVideoPage: (countryCode: string, page: number): string => `app:videolist:trending:${countryCode}:page:${page}`, // ───────────────────────────────────────────── // VIDEO DETAILS & METADATA // ───────────────────────────────────────────── /** Get cache key for video detail data. */ appVideoDetailKey: (videoId: string): string => `app:video:detail:${videoId}`, /** Get cache key for video category list by channel. */ appVideoCategoryListKey: (channelId: string): string => `app:video:category:list:${channelId}`, /** Get cache key for video tag list by channel and category. */ appVideoTagListKey: (channelId: string, categoryId: string): string => `app:video:tag:list:${channelId}:${categoryId}`, // ───────────────────────────────────────────── // VIDEO POOLS (sorted listings) // ───────────────────────────────────────────── /** Get cache key for videos in a category with sort order. */ appVideoCategoryPoolKey: ( channelId: string, categoryId: string, sort: VideoSortKey, ): string => `app:video:list:category:${channelId}:${categoryId}:${sort}`, /** Get cache key for videos with a specific tag with sort order. */ appVideoTagPoolKey: ( channelId: string, tagId: string, sort: VideoSortKey, ): string => `app:video:list:tag:${channelId}:${tagId}:${sort}`, /** Get cache key for home page video section. */ appVideoHomeSectionKey: ( channelId: string, section: VideoHomeSectionKey, ): string => `app:video:list:home:${channelId}:${section}`, };