| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { LatestVideosCacheBuilder } from '@box/core/cache/video/latest/latest-videos-cache.builder';
- import { RecommendedVideosCacheBuilder } from '@box/core/cache/video/recommended/recommended-videos-cache.builder';
- import { TagCacheBuilder } from '@box/core/cache/tag/tag-cache.builder';
- import { CategoryCacheBuilder } from '@box/core/cache/category/category-cache.builder';
- import { ChannelCacheBuilder } from '@box/core/cache/channel/channel-cache.builder';
- import { AdPoolBuilder } from '@box/core/ad/ad-pool.builder';
- export type RedisCacheCode =
- | 'VIDEO_LATEST'
- | 'VIDEO_RECOMMENDED'
- | 'TAG_ALL'
- | 'CATEGORY_ALL'
- | 'CATEGORY_BY_ID'
- | 'CHANNEL_ALL'
- | 'CHANNEL_BY_ID'
- | 'ADPOOL';
- export interface RedisCacheRebuildHandler {
- cacheCode: RedisCacheCode;
- label: string;
- description?: string;
- rebuild: () => Promise<{ ok: boolean; message?: string; affected?: number }>;
- }
- interface RedisCacheRegistryDeps {
- latestVideosCacheBuilder: LatestVideosCacheBuilder;
- recommendedVideosCacheBuilder: RecommendedVideosCacheBuilder;
- tagCacheBuilder: TagCacheBuilder;
- categoryCacheBuilder: CategoryCacheBuilder;
- channelCacheBuilder: ChannelCacheBuilder;
- adPoolBuilder: AdPoolBuilder;
- }
- export function getRedisCacheRegistry(
- deps: RedisCacheRegistryDeps,
- ): RedisCacheRebuildHandler[] {
- return [
- {
- cacheCode: 'VIDEO_LATEST',
- label: 'Latest Videos Cache',
- description: 'Rebuilds the latest video feed cache.',
- rebuild: async () => {
- await deps.latestVideosCacheBuilder.buildAll();
- return {
- ok: true,
- message: 'Latest videos cache rebuilt',
- };
- },
- },
- {
- cacheCode: 'VIDEO_RECOMMENDED',
- label: 'Recommended Videos Cache',
- description: 'Rebuilds the homepage recommended video cache.',
- rebuild: async () => {
- await deps.recommendedVideosCacheBuilder.buildAll();
- return {
- ok: true,
- message: 'Recommended videos cache rebuilt',
- };
- },
- },
- {
- cacheCode: 'TAG_ALL',
- label: 'Tag Cache',
- description: 'Rebuilds the global tag metadata cache.',
- rebuild: async () => {
- await deps.tagCacheBuilder.buildAll();
- return { ok: true, message: 'Tag cache rebuilt' };
- },
- },
- {
- cacheCode: 'CATEGORY_ALL',
- label: 'Category Cache (all)',
- description: 'Rebuilds the full category listing cache.',
- rebuild: async () => {
- await deps.categoryCacheBuilder.buildAll();
- return { ok: true, message: 'Category cache rebuilt' };
- },
- },
- {
- cacheCode: 'CHANNEL_ALL',
- label: 'Channel Cache (all)',
- description: 'Rebuilds the complete channel cache.',
- rebuild: async () => {
- await deps.channelCacheBuilder.buildAll();
- return { ok: true, message: 'Channel cache rebuilt' };
- },
- },
- {
- cacheCode: 'ADPOOL',
- label: 'Ad Pools',
- description: 'Rebuilds all ad pools.',
- rebuild: async () => {
- await deps.adPoolBuilder.buildAll();
- return { ok: true, message: 'Ad pools rebuilt' };
- },
- },
- ];
- }
- export interface RedisCacheKeyAllowListEntry {
- cacheCode: RedisCacheCode;
- matcher: (key: string) => boolean;
- description: string;
- }
- export const RedisCacheKeyAllowList: RedisCacheKeyAllowListEntry[] = [
- {
- cacheCode: 'VIDEO_LATEST',
- matcher: (key) => key === 'box:app:video:latest',
- description: 'Latest videos key',
- },
- {
- cacheCode: 'VIDEO_RECOMMENDED',
- matcher: (key) => key === 'box:app:video:recommended',
- description: 'Recommended videos key',
- },
- {
- cacheCode: 'TAG_ALL',
- matcher: (key) => key === 'box:app:tag:all',
- description: 'Global tag metadata key',
- },
- {
- cacheCode: 'CATEGORY_ALL',
- matcher: (key) => key === 'box:app:category:all',
- description: 'Category all key',
- },
- {
- cacheCode: 'CATEGORY_BY_ID',
- matcher: (key) => key.startsWith('box:app:category:by-id:'),
- description: 'Category detail key',
- },
- {
- cacheCode: 'CHANNEL_ALL',
- matcher: (key) => key === 'box:app:channel:all',
- description: 'Channel all key',
- },
- {
- cacheCode: 'CHANNEL_BY_ID',
- matcher: (key) => key.startsWith('box:app:channel:by-id:'),
- description: 'Channel detail key',
- },
- {
- cacheCode: 'ADPOOL',
- matcher: (key) => key.startsWith('box:app:adpool:'),
- description: 'Ad pool key',
- },
- ];
|